summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2026-03-01 00:21:10 +0800
committerlittleblack111 <littleblack11111@gmail.com>2026-03-01 00:27:02 +0800
commita3699d7e0ae13b3b42aecf390527b207931ced1d (patch)
treef2a72d1569d63551127889d7119dd091455bcc3c
parent32ea522f854d1d3d8fbeb6733f16265bad65ec6d (diff)
hyprshutdown: cleanup
-rwxr-xr-xhyprshutdown.sh54
1 files changed, 37 insertions, 17 deletions
diff --git a/hyprshutdown.sh b/hyprshutdown.sh
index 77c69d0..3daf7ee 100755
--- a/hyprshutdown.sh
+++ b/hyprshutdown.sh
@@ -1,36 +1,56 @@
#!/usr/bin/bash
WAIT=10 # in seconds
-self=$$
-cancel="Cancel"
-confirm="Confirm"
-DUP_ACTION=kill # or shutdown
-DUP_AMOUNT=3 # this only matters if its shutdown
+SELF=$$
+CANCEL="Cancel"
+CONFIRM="Confirm"
+DUP_ACTION=reboot # or shutdown or reboot
+DUP_AMOUNT=2 # this only matters if its shutdown or reboot
+# maybe add hyprsession --save or whatever thats called to restore prev apps
SHUTDOWN="hyprshutdown --post-cmd poweroff"
+REBOOT="hyprshutdown --post-cmd reboot"
+# default
+ACTION=Shutdown
other_pids=$(pidof -x -o $$ "$(basename "$0")")
dup_count=$(echo "$other_pids" | wc -w)
+# kill dialog RAII
+trap 'kill -- -$$' EXIT
+
+function exec_action {
+ if [[ $ACTION == "Shutdown" ]]; then
+ $SHUTDOWN &!
+ elif [[ $ACTION == "Reboot" ]]; then
+ $REBOOT &!
+ fi
+ kill $SELF
+}
+
+function dialog {
+ ans=$(timeout 1.2 hyprland-dialog --apptitle hyprshutdown --title "$ACTION in $1" --buttons "$CANCEL;$CONFIRM")
+ if [[ $ans == $CONFIRM ]]; then
+ exec_action
+ elif [[ $ans == $CANCEL ]]; then
+ kill $SELF
+ fi
+}
+
if [[ $DUP_ACTION == "kill" ]]; then
if [ $dup_count -gt 0 ]; then
kill $other_pids
fi
elif [[ $DUP_ACTION == "shutdown" ]]; then
- if [ $dup_count -ge DUP_AMOUNT ]; then
- $SHUTDOWN &!
+ if [ $dup_count -ge $DUP_AMOUNT ]; then
kill $other_pids
+ exec_action
fi
-fi
-
-function dialog {
- ans=$(timeout 1.2 hyprland-dialog --apptitle hyprshutdown --title "Shutting down in $1" --buttons "$cancel;$confirm")
- if [[ $ans == $confirm ]]; then
- $SHUTDOWN &!
- kill $self
- elif [[ $ans == $cancel ]]; then
- kill $self
+elif [[ $DUP_ACTION == "reboot" ]]; then
+ if [ $dup_count -ge $DUP_AMOUNT ]; then
+ kill $other_pids
+ ACTION=Reboot
fi
-}
+fi
for ((i=WAIT; i>=0; i--)); do
dialog $i &