| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | source "$(dirname "$0")/_lib.sh" |
| 4 | |
| 5 | if [[ $1 == --wlogout ]] && has wlogout; then |
| 6 | exec wlogout -b 5 -T 400 -B 400 |
| 7 | fi |
| 8 | |
| 9 | lock=$' Lock' |
| 10 | logout=$' Log out' |
| 11 | suspend=$' Suspend' |
| 12 | hibernate=$' Hibernate' |
| 13 | reboot=$' Reboot' |
| 14 | shutdown=$' Shut down' |
| 15 | |
| 16 | choice=$(printf '%s\n' "$lock" "$suspend" "$logout" "$reboot" "$shutdown" "$hibernate" \ |
| 17 | | menu "Power" --width 260 --height 290 --lines 6) || exit 0 |
| 18 | |
| 19 | confirm() { |
| 20 | [[ $(printf 'No\nYes\n' | menu "$1?" --width 200 --height 130 --lines 2) == Yes ]] |
| 21 | } |
| 22 | |
| 23 | case $choice in |
| 24 | "$lock") swaylock -f ;; |
| 25 | "$suspend") systemctl suspend ;; |
| 26 | "$hibernate") confirm Hibernate && systemctl hibernate ;; |
| 27 | "$logout") confirm "Log out" && swaymsg exit ;; |
| 28 | "$reboot") confirm Reboot && systemctl reboot ;; |
| 29 | "$shutdown") confirm "Shut down" && systemctl poweroff ;; |
| 30 | esac |