From efa790b4dcd0cffada76566316153f4b2d36bafe Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Wed, 25 Feb 2026 01:21:07 +0800 Subject: hyprshutdown: consider dupe --- hyprshutdown.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/hyprshutdown.sh b/hyprshutdown.sh index 9e78c91..1153c19 100755 --- a/hyprshutdown.sh +++ b/hyprshutdown.sh @@ -1,14 +1,30 @@ -#!/usr/bin/env sh +#!/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 + +other_pids=$(pidof -x -o $$ "$(basename "$0")") +dup_count=$(echo "$other_pids" | wc -w) + +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 + hyprshutdown &! + kill $other_pids + fi +fi function dialog { ans=$(timeout 1.2 hyprland-dialog --apptitle hyprshutdown --title "Shutting down in $1" --buttons "$cancel;$confirm") if [[ $ans == $confirm ]]; then - hyprshutdown + hyprshutdown &! kill $self elif [[ $ans == $cancel ]]; then kill $self -- cgit v1.2.3