Rely fully on the symlinks

This commit is contained in:
David Heinemeier Hansson
2025-06-18 21:56:22 +02:00
parent 50672c617e
commit 42e608a576

View File

@ -1,27 +1,39 @@
#!/bin/bash #!/bin/bash
THEMES_DIR="$HOME/.config/omarchy/themes/" THEMES_DIR="$HOME/.config/omarchy/themes/"
NEXT_THEME_FILE="$HOME/.cache/next_theme_index" CURRENT_THEME_LINK="$HOME/.config/omarchy/current-theme"
THEMES=($(find "$THEMES_DIR" -mindepth 1 | sort)) THEMES=($(find "$THEMES_DIR" -mindepth 1 | sort))
TOTAL=${#THEMES[@]} TOTAL=${#THEMES[@]}
if [[ ! -f "$NEXT_THEME_FILE" ]]; then # Get current theme from symlink
INDEX=0 if [[ -L "$CURRENT_THEME_LINK" ]]; then
CURRENT_THEME=$(readlink "$CURRENT_THEME_LINK")
else else
INDEX=$(<"$NEXT_THEME_FILE") # Default to first theme if no symlink exists
CURRENT_THEME=${THEMES[0]}
fi fi
# Set new theme # Find current theme index
NEW_THEME=${THEMES[$INDEX]} INDEX=0
ln -nsf $NEW_THEME ~/.config/omarchy/current-theme for i in "${!THEMES[@]}"; do
if [[ "${THEMES[$i]}" == "$CURRENT_THEME" ]]; then
INDEX=$i
break
fi
done
# Save next index (wrap around) # Get next theme (wrap around)
echo "$(((INDEX + 1) % TOTAL))" >"$NEXT_THEME_FILE" NEXT_INDEX=$(((INDEX + 1) % TOTAL))
NEW_THEME=${THEMES[$NEXT_INDEX]}
# Set new theme
ln -nsf $NEW_THEME ~/.config/omarchy/current-theme
# Install theme backgrounds # Install theme backgrounds
source ~/.config/omarchy/current-theme/backgrounds.sh source ~/.config/omarchy/current-theme/backgrounds.sh
ln -nsf ~/.config/omarchy/backgrounds/catpuccin ~/.config/omarchy/current-backgrounds THEME_NAME=$(basename "$NEW_THEME")
ln -nsf ~/.config/omarchy/backgrounds/$THEME_NAME ~/.config/omarchy/current-backgrounds
# Touch alacritty config to pickup the changed theme # Touch alacritty config to pickup the changed theme
touch ~/.config/alacritty/alacritty.toml touch ~/.config/alacritty/alacritty.toml