2011-06-03 17:44:54 +00:00
|
|
|
#!/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
|
2013-03-11 03:26:58 +00:00
|
|
|
# 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)
|
2013-11-03 03:18:16 +00:00
|
|
|
# * Add support for the user to specify a timer *needs some work yet*
|
2013-03-19 22:36:19 +00:00
|
|
|
# - Needs to provide a way to cancel the time
|
|
|
|
# - Would be nice if there was some notification when there's n min left in the timer
|
2013-03-11 03:26:58 +00:00
|
|
|
# * 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
|
2011-06-03 17:44:54 +00:00
|
|
|
|
2013-11-03 03:18:16 +00:00
|
|
|
actionNames=(logout suspend hibernate hybrid-sleep shutdown restart)
|
|
|
|
actionExecs=("xdotool key super+control+shift+End"
|
2013-03-11 03:26:58 +00:00
|
|
|
"xscreensaver-command -lock && systemctl suspend"
|
|
|
|
"xscreensaver-command -lock && systemctl hibernate"
|
|
|
|
"xscreensaver-command -lock && systemctl hybrid-sleep"
|
2013-03-19 22:36:19 +00:00
|
|
|
"shutdown -h now"
|
|
|
|
"reboot")
|
2013-03-11 03:26:58 +00:00
|
|
|
|
|
|
|
# Ask the user whether they want to logout, cancel, suspend, hibernate, hybrid-sleep, shutdown
|
2013-11-03 03:18:16 +00:00
|
|
|
ask=`echo "cancel ${actionNames[*]} timed-action" | tr ' ' '\n' | dmenu -b -i -nb '#040404' -nf '#525252' -sf '#ffa0ff' -sb '#000000'`
|
2013-03-11 03:26:58 +00:00
|
|
|
|
|
|
|
case "$ask" in
|
2013-11-03 03:18:16 +00:00
|
|
|
logout|suspend|hibernate|hybrid-sleep|shutdown|restart|timed-action)
|
|
|
|
if [[ "$ask" == "timed-action" ]]; then
|
|
|
|
time=`echo "1m 3m 5m 10m 15m 20m 30m 45m 1h 1.5h 2h 3h" | tr ' ' '\n' | dmenu -b -i -nb '#040404' -nf '#525252' -sf '#ffa0ff' -sb '#000000' -p "How long?"`
|
|
|
|
# TODO: validate input to ensure form: <digit>+(s|m|h|d)?
|
|
|
|
for ((i=0; i < ${#actionNames[*]}; i++)); do
|
|
|
|
actionExecs[$i]="sleep $time && notify-send 'WARNING! Computer set to ${actionNames[$i]} in 15 seconds!' -u critical && sleep 15s && ${actionExecs[$i]}"
|
|
|
|
done
|
|
|
|
ask=`echo "cancel ${actionNames[*]}" | tr ' ' '\n' | dmenu -b -i -nb '#040404' -nf '#525252' -sf '#ffa0ff' -sb '#000000'`
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$ask" != "cancel" && `echo "" | dmenu -b -i -nb '#040404' -nf '#525252' -sf '#ffa0ff' -sb '#000000' -p "Are you sure you want to $ask? [yes/no] "` == 'yes' ]]; then
|
2013-03-11 03:26:58 +00:00
|
|
|
for ((i=0; i < ${#actionNames[*]}; i++)); do
|
|
|
|
if [[ "$ask" == "${actionNames[$i]}" ]]; then
|
|
|
|
sh -c "${actionExecs[$i]}"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
cancel|*)
|
|
|
|
# Do nothing; the user entered cancel or a invalid input
|
|
|
|
;;
|
|
|
|
esac
|
2013-11-03 03:18:16 +00:00
|
|
|
|
|
|
|
# Exit successfully
|
|
|
|
exit 0
|