commit 0ae54e97144ea0f857ea31be8975eb6989a02128 Spenser Truex <truex@equwal.com> 2025-09-01 18:59:13 -0400 Add dsysact
README.md | 1 + dsysact | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
diff --git a/README.md b/README.md index dadb44f..6a91159 100644 --- a/README.md +++ b/README.md @@ -16,5 +16,6 @@ with that. - `dbrowsel`: select a browser for the link in the clipboard to open - `dmenu_run/dsudo`: run programs, maybe from a keybind set with xbindkeys or a wm - `dshow`: run a command and show output without having to open a terminal +- `dsysact`: reboot/shutdown/etc. - `passmenu`: unix [`pass`](https://www.passwordstore.org/) interface - `y-or-n`: ask if yes or no diff --git a/dsysact b/dsysact new file mode 100755 index 0000000..c9c0440 --- /dev/null +++ b/dsysact @@ -0,0 +1,26 @@ +#!/bin/sh + +# A dmenu wrapper script for system functions. +export WM="dwm" +case "$(readlink -f /sbin/init)" in + *systemd*) ctl='systemctl' ;; + *) ctl='loginctl' ;; +esac + +wmpid(){ # This function is needed if there are multiple instances of the window manager. + tree="$(pstree -ps $$)" + tree="${tree#*$WM(}" + echo "${tree%%)*}" +} + +case "$(printf "🔒 lock\n🚪 leave $WM\n♻️ renew $WM\n🐻 hibernate\n🔃 reboot\n🖥️shutdown\n💤 sleep\n📺 display off" | dmenu -i -p 'Action: ')" in + 'lock') slock ;; + "leave $WM") kill -TERM "$(wmpid)" ;; + "renew $WM") kill -HUP "$(wmpid)" ;; + 'hibernate') slock $ctl hibernate -i ;; + 'sleep') slock $ctl suspend -i ;; + 'reboot') $ctl reboot -i ;; + 'shutdown') $ctl poweroff -i ;; + 'display off') xset dpms force off ;; + *) exit 1 ;; +esac