aboutsummaryrefslogtreecommitdiff
path: root/.local/bin
diff options
context:
space:
mode:
authorawy <awy@awy.one>2025-11-12 23:12:31 +0300
committerawy <awy@awy.one>2025-11-12 23:12:31 +0300
commitf748c9dbf2d84eca7e0942ce9d5fa0f0baa8928d (patch)
tree673812734f422f64fa9ec339e93f59f4e5e60cdb /.local/bin
parent04b02944c688a989d29044a572417313b52babea (diff)
downloadhyprdots-f748c9dbf2d84eca7e0942ce9d5fa0f0baa8928d.tar.gz
fixes
Diffstat (limited to '.local/bin')
-rwxr-xr-x.local/bin/randombg20
1 files changed, 17 insertions, 3 deletions
diff --git a/.local/bin/randombg b/.local/bin/randombg
index 61704bf..a38daaa 100755
--- a/.local/bin/randombg
+++ b/.local/bin/randombg
@@ -7,15 +7,29 @@ if [ -e "$PIDFILE" ] && kill -0 "$(bat "$PIDFILE")"; then
kill -9 "$(bat $PIDFILE)" # Forcefully kill the old process
fi
echo $$ > "$PIDFILE"
-trap 'rm -f "$PIDFILE"; exit' INT TERM EXIT
+
+cleanup() {
+ [ -n "$OLD_PID" ] && kill "$OLD_PID" 2>/dev/null
+ rm -f "$PIDFILE"
+ exit 0
+}
+trap cleanup INT TERM EXIT
+
+sleep_interruptible() {
+ t=$1
+ while [ "$t" -gt 0 ]; do
+ sleep 1 || return
+ t=$((t-1))
+ done
+}
swaybg -i "$(fd . /mnt/ssd/papes -t f | shuf -n1)" -m fill &
OLD_PID=$!
while true; do
- sleep 300
+ sleep_interruptible 300
swaybg -i "$(fd . /mnt/ssd/papes -t f | shuf -n1)" -m fill &
NEXT_PID=$!
- sleep 5
+ sleep_interruptible 5
kill $OLD_PID
OLD_PID=$NEXT_PID
done