nixos-config/home-manager/modules/sway/powermenu.sh

64 lines
1.2 KiB
Bash
Raw Normal View History

# shellcheck disable=SC2148
2021-11-22 08:04:54 +01:00
confirm() {
rofi -dmenu \
-i \
-no-fixed-num-lines \
-p "Are you sure? [y/n]: " \
-theme power
2021-11-22 08:04:54 +01:00
}
# Options
shutdown=""
reboot=""
lock=""
hibernate=""
exit_wm=""
#shutdown="S"
#reboot="R"
#lock="L"
#hibernate="S"
#exit_wm="E"
# Variable passed to rofi
options="${shutdown}\n${reboot}\n${lock}\n${hibernate}\n${exit_wm}"
uptime=$(uptime | awk '{print $1}' || true)
lockcmd="swaylock --ignore-empty-password --daemonize --show-failed-attempts --indicator-caps-lock --image /home/erwin/.wallpapers/river-2560.png --scaling fill"
2021-11-22 08:04:54 +01:00
chosen="$(echo -e "${options}" | rofi -theme power -p "Uptime: ${uptime}" -dmenu -selected-row 2)"
if [[ ${chosen} == "" ]]; then
exit 0
2021-11-22 08:04:54 +01:00
fi
if [[ ${chosen} == "${lock}" ]]; then
${lockcmd}
exit 0
2021-11-22 08:04:54 +01:00
fi
answer=$(confirm)
if [[ ${answer} == "y" ]]; then
case "${chosen}" in
"${shutdown}")
systemctl poweroff
;;
"${reboot}")
systemctl reboot
;;
"${hibernate}")
${lockcmd}
systemctl hibernate
;;
"${exit_wm}")
if [[ ${XDG_CURRENT_DESKTOP} == "sway" ]]; then
swaymsg exit
elif [[ ${XDG_CURRENT_DESKTOP} == "Hyprland" ]]; then
hyprctl dispatch exit
fi
;;
*) ;;
esac
2021-11-22 08:04:54 +01:00
fi