Use symlinks instead

This commit is contained in:
David Heinemeier Hansson
2025-06-18 22:00:47 +02:00
parent 42e608a576
commit e8f457b82a

View File

@ -3,20 +3,35 @@
# Cycles through the background images available # Cycles through the background images available
BACKGROUNDS_DIR="$HOME/.config/omarchy/current-backgrounds/" BACKGROUNDS_DIR="$HOME/.config/omarchy/current-backgrounds/"
NEXT_BACKGROUND_FILE="$HOME/.cache/next_background_index" CURRENT_BACKGROUND_LINK="$HOME/.config/omarchy/current-background"
BACKGROUNDS=($(find "$BACKGROUNDS_DIR" -type f | sort)) BACKGROUNDS=($(find "$BACKGROUNDS_DIR" -type f | sort))
TOTAL=${#BACKGROUNDS[@]} TOTAL=${#BACKGROUNDS[@]}
if [[ ! -f "$NEXT_BACKGROUND_FILE" ]]; then # Get current background from symlink
INDEX=0 if [[ -L "$CURRENT_BACKGROUND_LINK" ]]; then
CURRENT_BACKGROUND=$(readlink "$CURRENT_BACKGROUND_LINK")
else else
INDEX=$(<"$NEXT_BACKGROUND_FILE") # Default to first background if no symlink exists
CURRENT_BACKGROUND=${BACKGROUNDS[0]}
fi fi
# Save next index (wrap around) # Find current background index
echo "$(((INDEX + 1) % TOTAL))" >"$NEXT_BACKGROUND_FILE" INDEX=0
for i in "${!BACKGROUNDS[@]}"; do
if [[ "${BACKGROUNDS[$i]}" == "$CURRENT_BACKGROUND" ]]; then
INDEX=$i
break
fi
done
# Get next background (wrap around)
NEXT_INDEX=$(((INDEX + 1) % TOTAL))
NEW_BACKGROUND=${BACKGROUNDS[$NEXT_INDEX]}
# Set new background symlink
ln -nsf "$NEW_BACKGROUND" "$CURRENT_BACKGROUND_LINK"
# Launch swaybg # Launch swaybg
pkill -x swaybg pkill -x swaybg
setsid swaybg -i "${BACKGROUNDS[$INDEX]}" -m fill >/dev/null 2>&1 & setsid swaybg -i "$NEW_BACKGROUND" -m fill >/dev/null 2>&1 &