This repository has been archived on 2022-12-11. You can view files and clone it, but cannot push or open issues or pull requests.
dot-files/.bin/xmonadClose.sh

60 lines
2.5 KiB
Bash
Executable File

#!/bin/sh
# (C) Copyright Collin Doering 2011
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# File: xmonadClose.sh
# Author: Collin J. Doering <rekahsoft@gmail.com>
# Date: May 13, 2011
# Description: A simple script to allow a nice dmenu gui when logging out,
# shutting down, or rebooting
# TODO: * Support sleep and hibernate
# * Needs to check whether a reboot/shutdown is allowed (user must be in the group
# 'power' and must be the only user logged in or they will be prompted for sudo's
# password to override)
# * re-write in haskell direct into ~/.xmonad/xmonad.hs using the dmenu extension(?)
# - issue with that is then the script could only be used within xmonad
# - perhaps consider taking a second argument when logout is passed as the first
# so that the second argument could be used as a 'logout command' and thus
# this script could be used with any wm
actionNames=(cancel logout suspend hibernate hybrid-sleep shutdown)
actionExecs=(""
"xdotool key super+control+shift+End"
"xscreensaver-command -lock && systemctl suspend"
"xscreensaver-command -lock && systemctl hibernate"
"xscreensaver-command -lock && systemctl hybrid-sleep"
"shutdown -h now")
# Ask the user whether they want to logout, cancel, suspend, hibernate, hybrid-sleep, shutdown
ask=`echo ${actionNames[*]} | tr ' ' '\n' | dmenu -b -i -nb '#040404' -nf '#525252' -sf '#ffa0ff' -sb '#000000'`
case "$ask" in
logout|suspend|hibernate|hybrid-sleep|shutdown)
if [[ `echo "" | dmenu -b -i -nb '#040404' -nf '#525252' -sf '#ffa0ff' -sb '#000000' -p "Are you sure you want to $ask? [yes/no] "` == 'yes' ]]; then
for ((i=0; i < ${#actionNames[*]}; i++)); do
if [[ "$ask" == "${actionNames[$i]}" ]]; then
sh -c "${actionExecs[$i]}"
break
fi
done
fi
break
;;
cancel|*)
# Do nothing; the user entered cancel or a invalid input
;;
esac