summaryrefslogtreecommitdiffstats
path: root/.local/bin/powercmd
blob: 9b83e4bec5b9acd9fe726a5daab3881f2669bd57 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh

[ -z "$1" ] && echo "no arg" && exit 1

os="$(uname)"

if [ "$os" = "Linux" ]; then
	grep "Artix" /etc/issue >/dev/null 2>&1 && os=1 || os=2
elif [ "$os" = "FreeBSD" ]; then
	os=3
else
	echo "unknown OS"
	exit 1
fi

# 1: Artix
# 2: Pop OS
# 3: FreeBSD

case $os in
	1) icon=" " ;;
	2) icon=" " ;;
	3) icon=" " ;;
esac

case $1 in
	"lock")		xscreensaver-command -lock ;;
	"sleep")
		notify-send -u normal "sleep" "$icon G'night, partner!"
		sleep 1
		xscreensaver-command -lock
		sleep 5
		case $os in
			1) loginctl suspend ;;
			2) systemctl suspend ;;
			3) acpiconf -s 3 ;;
		esac
		;;
	"reboot")
		emacsclient -e '"(save-buffers-kill-emacs)"' >/dev/null 2>&1
		notify-send -u normal reboot "$icon Rebootin' now!"
		sleep 2
		case $os in
			1) loginctl reboot ;;
			2) systemctl reboot ;;
			3) shutdown -r now ;;
		esac
		;;
	"poweroff")
		emacsclient -e '"(save-buffers-kill-emacs)"' >/dev/null 2>&1
		notify-send -u normal poweroff "$icon Farewell, partner!"
		sleep 2
		case $os in
			1) loginctl poweroff ;;
			2) systemctl poweroff ;;
			3) shutdown -p now ;;
		esac
		;;
	*)
		echo "wrong arg"
		exit 1
		;;
esac