laptop-config/home/wallpaper-rotate.sh

28 lines
742 B
Bash
Executable file

#!/usr/bin/env bash
set -o pipefail
# Ensure awww-daemon is running
if ! pgrep -x "awww-daemon" > /dev/null 2>&1; then
awww-daemon &
sleep 0.3
fi
WALLPAPER_DIR="$HOME/laptop-config/wallpapers"
CACHE_FILE="$HOME/.cache/current-wallpaper"
mapfile -t wallpapers < <(find "$WALLPAPER_DIR" -maxdepth 1 -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.gif" \) | sort)
count="${#wallpapers[@]}"
if [ "$count" -eq 0 ]; then
echo "No wallpapers found in $WALLPAPER_DIR"
exit 1
fi
current=$(cat "$CACHE_FILE" 2>/dev/null || echo "")
chosen="$current"
while [ "$chosen" = "$current" ] && [ "$count" -gt 1 ]; do
chosen="${wallpapers[$((RANDOM % count))]}"
done
echo "$chosen" > "$CACHE_FILE"
awww img "$chosen"