summaryrefslogtreecommitdiffstats
path: root/.local/bin/powercmd
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/powercmd')
-rwxr-xr-x.local/bin/powercmd63
1 files changed, 63 insertions, 0 deletions
diff --git a/.local/bin/powercmd b/.local/bin/powercmd
new file mode 100755
index 0000000..9f85e39
--- /dev/null
+++ b/.local/bin/powercmd
@@ -0,0 +1,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 hibernate ;;
+ 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