Feed dmenuexit the commands from i3exit.

This commit is contained in:
dabruh 2022-06-07 12:54:09 +02:00
parent aa1f40e58d
commit 51c3918628
2 changed files with 13 additions and 24 deletions

View File

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
ACTION="$(xargs -n 1 <<<"Lock Suspend Hibernate Logout Shutdown Reboot" | dmenu -i -p "exitctl")" COMMANDS="$(i3exit commands | sed 's/\,/\ /g' | sed 's/.*/\L&/; s/[a-z]*/\u&/g')"
ACTION="$(xargs -n 1 <<<"$COMMANDS" | dmenu -i -p "exitctl")"
[ -z "$ACTION" ] && exit 1 [ -z "$ACTION" ] && exit 1
echo "INFO: Selected action $ACTION." echo "INFO: Selected action $ACTION."
@ -9,26 +10,7 @@ CONFIRMATION="$(xargs -n 1 <<<"No Yes" | dmenu -i -p "Are you sure you want to $
echo "INFO: Action confirmed." echo "INFO: Action confirmed."
case "${ACTION,,}" in if ! i3exit "${ACTION,,}"; then
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 echo "ERROR: Invalid action '${ACTION,,}'." 1>&2
;; exit 2
esac fi

View File

@ -37,9 +37,16 @@ case "$1" in
shutdown) shutdown)
$logind poweroff $logind poweroff
;; ;;
commands)
echo "lock,logout,switch_user,suspend,hibernate,reboot,shutdown"
;;
help)
cmds="$($0 commands)"
echo "Usage: $0 ${cmds//\,/\, }"
;;
*) *)
echo "== ! i3exit: missing or invalid argument ! ==" echo "== ! i3exit: missing or invalid argument ! =="
echo "Try again with: lock | logout | switch_user | suspend | hibernate | reboot | shutdown" $0 help
exit 2 exit 2
esac esac