mirror of
https://github.com/basecamp/omarchy.git
synced 2026-02-17 15:25:37 +00:00
Explicitly store the name of the current theme
This commit is contained in:
@@ -1,48 +1,38 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
CURRENT_THEME_LINK="$HOME/.config/omarchy/current/theme"
|
# Get all theme names (user themes override default by name)
|
||||||
|
declare -A seen
|
||||||
|
THEMES=()
|
||||||
|
|
||||||
declare -A theme_paths
|
for dir in ~/.config/omarchy/themes "$OMARCHY_PATH/themes"; do
|
||||||
|
for path in "$dir"/*/; do
|
||||||
while IFS= read -r path; do
|
[[ -d "$path" ]] || continue
|
||||||
name=$(basename "$path")
|
name=$(basename "$path")
|
||||||
theme_paths[$name]="$path"
|
if [[ -z "${seen[$name]}" ]]; then
|
||||||
done < <(find ~/.config/omarchy/themes/ -mindepth 1 -maxdepth 1 \( -type d -o -type l \) | sort)
|
seen[$name]=1
|
||||||
|
THEMES+=("$name")
|
||||||
while IFS= read -r path; do
|
|
||||||
name=$(basename "$path")
|
|
||||||
if [[ -z "${theme_paths[$name]}" ]]; then
|
|
||||||
theme_paths[$name]="$path"
|
|
||||||
fi
|
fi
|
||||||
done < <(find "$OMARCHY_PATH/themes/" -mindepth 1 -maxdepth 1 -type d | sort)
|
done
|
||||||
|
done
|
||||||
|
|
||||||
IFS=$'\n' THEMES=($(for name in "${!theme_paths[@]}"; do echo "$name"; done | sort))
|
IFS=$'\n' THEMES=($(printf '%s\n' "${THEMES[@]}" | sort))
|
||||||
IFS=$'\n' THEMES_FULL=($(for name in "${!theme_paths[@]}"; do echo "${theme_paths[$name]}"; done | sort))
|
|
||||||
|
|
||||||
TOTAL=${#THEMES[@]}
|
# Get current theme name
|
||||||
|
if [[ -f "$HOME/.config/omarchy/current/theme.name" ]]; then
|
||||||
# Get current theme from symlink
|
CURRENT=$(cat "$HOME/.config/omarchy/current/theme.name")
|
||||||
if [[ -L "$CURRENT_THEME_LINK" ]]; then
|
|
||||||
CURRENT_THEME=$(realpath "$CURRENT_THEME_LINK")
|
|
||||||
else
|
else
|
||||||
# Default to first theme if no symlink exists
|
CURRENT=""
|
||||||
CURRENT_THEME=$(realpath "${THEMES_FULL[0]}")
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Find current theme index
|
# Find next theme
|
||||||
INDEX=0
|
TOTAL=${#THEMES[@]}
|
||||||
for i in "${!THEMES_FULL[@]}"; do
|
for i in "${!THEMES[@]}"; do
|
||||||
THEME_REAL=$(realpath "${THEMES_FULL[$i]}")
|
if [[ "${THEMES[$i]}" == "$CURRENT" ]]; then
|
||||||
|
NEXT_INDEX=$(((i + 1) % TOTAL))
|
||||||
if [[ "$THEME_REAL" == "$CURRENT_THEME" ]]; then
|
|
||||||
INDEX=$i
|
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
NEXT_INDEX=${NEXT_INDEX:-0}
|
||||||
|
|
||||||
# Get next theme (wrap around)
|
omarchy-theme-set "${THEMES[$NEXT_INDEX]}"
|
||||||
NEXT_INDEX=$(((INDEX + 1) % TOTAL))
|
notify-send "Theme changed to ${THEMES[$NEXT_INDEX]}" -t 2000
|
||||||
NEW_THEME_NAME=${THEMES[$NEXT_INDEX]}
|
|
||||||
|
|
||||||
omarchy-theme-set $NEW_THEME_NAME
|
|
||||||
notify-send "Theme changed to $NEW_THEME_NAME" -t 2000
|
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ omarchy-theme-set-templates
|
|||||||
rm -rf "$CURRENT_THEME_PATH"
|
rm -rf "$CURRENT_THEME_PATH"
|
||||||
mv "$NEXT_THEME_PATH" "$CURRENT_THEME_PATH"
|
mv "$NEXT_THEME_PATH" "$CURRENT_THEME_PATH"
|
||||||
|
|
||||||
|
# Store theme name for reference
|
||||||
|
echo "$THEME_NAME" > "$HOME/.config/omarchy/current/theme.name"
|
||||||
|
|
||||||
# Change background with theme
|
# Change background with theme
|
||||||
omarchy-theme-bg-next
|
omarchy-theme-bg-next
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ CURRENT_THEME_LINK="$HOME/.config/omarchy/current/theme"
|
|||||||
CURRENT_THEME_NAME=""
|
CURRENT_THEME_NAME=""
|
||||||
if [[ -L $CURRENT_THEME_LINK ]]; then
|
if [[ -L $CURRENT_THEME_LINK ]]; then
|
||||||
CURRENT_THEME_NAME=$(basename "$(readlink "$CURRENT_THEME_LINK")")
|
CURRENT_THEME_NAME=$(basename "$(readlink "$CURRENT_THEME_LINK")")
|
||||||
|
elif [[ -f "$HOME/.config/omarchy/current/theme.name" ]]; then
|
||||||
|
CURRENT_THEME_NAME=$(cat "$HOME/.config/omarchy/current/theme.name")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove all symlinks from ~/.config/omarchy/themes
|
# Remove all symlinks from ~/.config/omarchy/themes
|
||||||
|
|||||||
Reference in New Issue
Block a user