| 1 | #!/bin/sh |
| 2 | |
| 3 | export WM="dwm" |
| 4 | case "$(readlink -f /sbin/init)" in |
| 5 | *systemd*) ctl='systemctl' ;; |
| 6 | *) ctl='loginctl' ;; |
| 7 | esac |
| 8 | |
| 9 | wmpid(){ # This function is needed if there are multiple instances of the window manager. |
| 10 | tree="$(pstree -ps $$)" |
| 11 | tree="${tree#*$WM(}" |
| 12 | echo "${tree%%)*}" |
| 13 | } |
| 14 | |
| 15 | |
| 16 | case "$(printf " lock\n leave $WM\n renew $WM\n hibernate\n reboot\n shutdown\n sleep\n display off" | dmenu -i -l 15 -p 'Action: ')" in |
| 17 | ' lock') slock ;; |
| 18 | " leave $WM") kill -TERM "$(wmpid)" ;; |
| 19 | " renew $WM") kill -HUP "$(wmpid)" ;; |
| 20 | ' hibernate') slock $ctl hibernate -i ;; |
| 21 | ' sleep') slock $ctl suspend -i ;; |
| 22 | ' reboot') $ctl reboot -i ;; |
| 23 | ' shutdown') $ctl poweroff -i ;; |
| 24 | ' display off') xset dpms force off ;; |
| 25 | *) exit 1 ;; |
| 26 | esac |