diff --git a/bin/omarchy-theme-next b/bin/omarchy-theme-next index d539da6..68e2dad 100755 --- a/bin/omarchy-theme-next +++ b/bin/omarchy-theme-next @@ -1,27 +1,39 @@ #!/bin/bash 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)) TOTAL=${#THEMES[@]} -if [[ ! -f "$NEXT_THEME_FILE" ]]; then - INDEX=0 +# Get current theme from symlink +if [[ -L "$CURRENT_THEME_LINK" ]]; then + CURRENT_THEME=$(readlink "$CURRENT_THEME_LINK") else - INDEX=$(<"$NEXT_THEME_FILE") + # Default to first theme if no symlink exists + CURRENT_THEME=${THEMES[0]} fi -# Set new theme -NEW_THEME=${THEMES[$INDEX]} -ln -nsf $NEW_THEME ~/.config/omarchy/current-theme +# Find current theme index +INDEX=0 +for i in "${!THEMES[@]}"; do + if [[ "${THEMES[$i]}" == "$CURRENT_THEME" ]]; then + INDEX=$i + break + fi +done -# Save next index (wrap around) -echo "$(((INDEX + 1) % TOTAL))" >"$NEXT_THEME_FILE" +# Get next theme (wrap around) +NEXT_INDEX=$(((INDEX + 1) % TOTAL)) +NEW_THEME=${THEMES[$NEXT_INDEX]} + +# Set new theme +ln -nsf $NEW_THEME ~/.config/omarchy/current-theme # Install theme backgrounds 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 ~/.config/alacritty/alacritty.toml