commit f17ea76b03f017184d6a9a827c40dcaa0e5b5c90 parent 15a215030990fde9a7abaa35658cc7690595e7fd Author: awy <awy@awy.one> Date: Fri, 11 Apr 2025 13:08:45 +0300 fix multiple instances Diffstat:
M | .local/bin/randombg | | | 10 | ++++++++++ |
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/.local/bin/randombg b/.local/bin/randombg @@ -1,4 +1,14 @@ #!/bin/sh +killall swaybg +PIDFILE="/tmp/randombg.pid" +# Check if the PID file exists and if the process is running +if [ -e "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")"; then + echo "Another instance of the script is already running." + kill -9 "$(cat $PIDFILE)" # Forcefully kill the old process +fi +echo $$ > "$PIDFILE" +trap 'rm -f "$PIDFILE"; exit' INT TERM EXIT + swaybg -i $(find /mnt/ssd/papes/. -type f | shuf -n1) -m fill & OLD_PID=$! while true; do