dotfiles/.local/bin/dmenuexit

35 lines
631 B
Bash
Executable File

#!/bin/bash
ACTION="$(xargs -n 1 <<<"Lock Suspend Hibernate Logout Shutdown Reboot" | dmenu -i -p "exitctl")"
[ -z "$ACTION" ] && exit 1
echo "INFO: Selected action $ACTION."
CONFIRMATION="$(xargs -n 1 <<<"No Yes" | dmenu -i -p "Are you sure you want to ${ACTION,,}?")"
{ [ -z "$CONFIRMATION" ] || [[ "$CONFIRMATION" != "Yes" ]]; } && exit 1
echo "INFO: Action confirmed."
case "${ACTION,,}" in
lock)
loginctl lock-session
;;
suspend)
systemctl suspend
;;
hibernate)
systemctl hibernate
;;
logout)
i3-msg exit
;;
shutdown)
poweroff
;;
reboot)
reboot
;;
*)
echo "ERROR: Invalid action '${ACTION,,}'." 1>&2
;;
esac