#!/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 . # File: xmonadClose.sh # Author: Collin J. Doering # 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) # * Add support for the user to specify a timer *needs some work yet* # - 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 # * 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=(logout suspend hibernate hybrid-sleep shutdown restart) 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" "reboot") # Ask the user whether they want to logout, cancel, suspend, hibernate, hybrid-sleep, shutdown ask=`echo "cancel ${actionNames[*]} timed-action" | tr ' ' '\n' | dmenu -b -i -nb '#040404' -nf '#525252' -sf '#ffa0ff' -sb '#000000'` case "$ask" in 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: +(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 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 # Exit successfully exit 0