Ethan Marshall 34e7d0dc78
Use non-admin tools to manage system power
Removes the requirement for the user running the script to enter the
administrator/sudo password to manage power (which causes lots of
strange issues with dmenu and focus etc.).
2021-04-05 19:50:43 +01:00

25 lines
674 B
Bash
Executable File

#!/bin/sh
# A dmenu wrapper script for system functions.
# For systemd-based systems.
case "$(readlink -f /sbin/init)" in
*systemd*)
hib="systemctl suspend-then-hibernate -i"
shut="systemctl poweroff -i"
reb="systemctl reboot -i";;
esac
cmds="\
🔒 lock slock
🚪 leave dwm kill -TERM $(pgrep -u $USER "\bdwm$")
♻ renew dwm kill -HUP $(pgrep -u $USER "\bdwm$")
🐻 hibernate slock ${hib:-loginctl suspend-then-hibernate -i}
🔃 reboot ${reb:-loginctl reboot -i}
🖥 shutdow ${shut:-systemctl poweroff -i}
📺 display off xset dpms force off"
choice="$(echo "$cmds" | cut -d' ' -f 1 | dmenu)" || exit 1
`echo "$cmds" | grep "^$choice " | cut -d ' ' -f2-`