aboutsummaryrefslogtreecommitdiff
path: root/dmenu-dwm-sessionmanager
blob: dafe8533c173887f304e22edba9a80326f6a5698 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh

# Prompts menu to shutdown/reboot/close dwm
# Requires: dmenu (or equivalent), dwm (optional)

# Usage: dmenu-dwm-sessionmanager [-m menu]

menu="dmenu -i"
prompt="Do you want to quit?"

usage() {
	echo "Usage: dmenu-dwm-sessionmanager [-m MENU]"
}

while getopts "m:" opt; do
	case "$opt" in
		m)
			menu="$OPTARG"
			;;
		*)
			usage
			exit 1
			;;
	esac
done
shift $((OPTIND - 1))

wmname="dwm"
shutdown_cmd="sudo shutdown -h now"
reboot_cmd="sudo reboot"
closewm_cmd="pkill $wmname"

value=$(printf 'Shutdown\nReboot\nQuit dwm\n' | $menu -p "$prompt")

if [ "$value" = "Shutdown" ]; then
	$shutdown_cmd
elif [ "$value" = "Reboot" ]; then
	$reboot_cmd
elif [ "$value" = "Quit $wmname" ]; then
	$closewm_cmd
fi

Generated with cgit - Back to sebastiano.tronto.net