diff options
author | Joe <bousset.rudy@gmail.com> | 2023-01-31 21:13:10 +0100 |
---|---|---|
committer | Joe <bousset.rudy@gmail.com> | 2023-01-31 21:13:10 +0100 |
commit | ae83bf5ca77c4cb3b6f219456e92d4c5e0f8fc9f (patch) | |
tree | 7341031ed0f84167350e95f48397761ef6544ad9 /.local/bin/powercmd | |
parent | fbsd merge (diff) | |
parent | up (diff) | |
download | dotfiles-bsd-ae83bf5ca77c4cb3b6f219456e92d4c5e0f8fc9f.tar.gz dotfiles-bsd-ae83bf5ca77c4cb3b6f219456e92d4c5e0f8fc9f.tar.bz2 dotfiles-bsd-ae83bf5ca77c4cb3b6f219456e92d4c5e0f8fc9f.tar.xz dotfiles-bsd-ae83bf5ca77c4cb3b6f219456e92d4c5e0f8fc9f.tar.zst dotfiles-bsd-ae83bf5ca77c4cb3b6f219456e92d4c5e0f8fc9f.zip |
Merge branch 'master' of gitjoe.xyz:dotfiles-bsd
Diffstat (limited to '')
-rwxr-xr-x | .local/bin/powercmd | 63 |
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 |