scripts

Various scripts for UNIX-like systems
git clone https://git.tronto.net/scripts
Download | Log | Files | Refs | README

dmenu-dwm-sessionmanager (726B)


      1 #!/bin/sh
      2 
      3 # Prompts menu to shutdown/reboot/close dwm
      4 # Requires: dmenu (or equivalent), dwm (optional)
      5 
      6 # Usage: dmenu-dwm-sessionmanager [-m menu]
      7 
      8 menu="dmenu -i"
      9 prompt="Do you want to quit?"
     10 
     11 usage() {
     12 	echo "Usage: dmenu-dwm-sessionmanager [-m MENU]"
     13 }
     14 
     15 while getopts "m:" opt; do
     16 	case "$opt" in
     17 		m)
     18 			menu="$OPTARG"
     19 			;;
     20 		*)
     21 			usage
     22 			exit 1
     23 			;;
     24 	esac
     25 done
     26 shift $((OPTIND - 1))
     27 
     28 wmname="dwm"
     29 shutdown_cmd="sudo shutdown -h now"
     30 reboot_cmd="sudo reboot"
     31 closewm_cmd="pkill $wmname"
     32 
     33 value=$(printf 'Shutdown\nReboot\nQuit dwm\n' | $menu -p "$prompt")
     34 
     35 if [ "$value" = "Shutdown" ]; then
     36 	$shutdown_cmd
     37 elif [ "$value" = "Reboot" ]; then
     38 	$reboot_cmd
     39 elif [ "$value" = "Quit $wmname" ]; then
     40 	$closewm_cmd
     41 fi
     42