aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/randombg
diff options
context:
space:
mode:
authorawy <awy@awy.one>2025-11-14 23:43:38 +0300
committerawy <awy@awy.one>2025-11-14 23:43:38 +0300
commitc7a88a07b9287db9c129914483f6b3ae1ab5404c (patch)
tree73c227c5e8519eb9135f46984e4fc067b316ed1b /.local/bin/randombg
downloadmangoslice-c7a88a07b9287db9c129914483f6b3ae1ab5404c.tar.gz
init
Diffstat (limited to '.local/bin/randombg')
-rwxr-xr-x.local/bin/randombg35
1 files changed, 35 insertions, 0 deletions
diff --git a/.local/bin/randombg b/.local/bin/randombg
new file mode 100755
index 0000000..e894a09
--- /dev/null
+++ b/.local/bin/randombg
@@ -0,0 +1,35 @@
+#!/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 "$(bat "$PIDFILE")"; then
+ echo "Another instance of the script is already running."
+ kill -9 "$(bat $PIDFILE)" # Forcefully kill the old process
+fi
+echo $$ > "$PIDFILE"
+
+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_interruptible 300
+ swaybg -i "$(fd . /mnt/ssd/papes -t f | shuf -n1)" -m fill &
+ NEXT_PID=$!
+ sleep_interruptible 5
+ kill $OLD_PID
+ OLD_PID=$NEXT_PID
+done