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.).
This commit is contained in:
Ethan Marshall 2021-04-05 19:50:43 +01:00
parent f05cb5e1bb
commit 34e7d0dc78
No known key found for this signature in database
GPG Key ID: EC2FAEF4DB8968D8

View File

@ -2,19 +2,21 @@
# A dmenu wrapper script for system functions. # A dmenu wrapper script for system functions.
# For non-systemd init systems. # For systemd-based systems.
case "$(readlink -f /sbin/init)" in case "$(readlink -f /sbin/init)" in
*runit*) hib="sudo -A zzz" ;; *systemd*)
*openrc*) reb="sudo -A openrc-shutdown -r"; shut="sudo -A openrc-shutdown -p 0" ;; hib="systemctl suspend-then-hibernate -i"
shut="systemctl poweroff -i"
reb="systemctl reboot -i";;
esac esac
cmds="\ cmds="\
🔒 lock slock 🔒 lock slock
🚪 leave dwm kill -TERM $(pgrep -u $USER "\bdwm$") 🚪 leave dwm kill -TERM $(pgrep -u $USER "\bdwm$")
♻ renew dwm kill -HUP $(pgrep -u $USER "\bdwm$") ♻ renew dwm kill -HUP $(pgrep -u $USER "\bdwm$")
🐻 hibernate slock ${hib:-systemctl suspend-then-hibernate -i} 🐻 hibernate slock ${hib:-loginctl suspend-then-hibernate -i}
🔃 reboot ${reb:-sudo -A reboot} 🔃 reboot ${reb:-loginctl reboot -i}
🖥 shutdown ${shut:-sudo -A shutdown -h now} 🖥 shutdow ${shut:-systemctl poweroff -i}
📺 display off xset dpms force off" 📺 display off xset dpms force off"
choice="$(echo "$cmds" | cut -d' ' -f 1 | dmenu)" || exit 1 choice="$(echo "$cmds" | cut -d' ' -f 1 | dmenu)" || exit 1