mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-12-19 20:29:45 +01:00
Add themes in $ZSH_CUSTOM to the pool of candidates
Also add comments and unset leftover variables, and print only the name of the theme loaded. When looking for $ZSH_CUSTOM themes, the chosen algorithm is to add the theme names to the pool disregarding the path, and then source whatever theme is selected with the same logic as the init script, which is to source first custom themes even if there is another default theme of the same name. Co-authored-by: Mihai Serban <mihai.serban@gmail.com>
This commit is contained in:
parent
6adad5c300
commit
b297bf9296
1 changed files with 31 additions and 7 deletions
|
@ -1,10 +1,34 @@
|
||||||
if [[ "${(t)ZSH_THEME_RANDOM_CANDIDATES}" = "array" ]] && [[ "${#ZSH_THEME_RANDOM_CANDIDATES[@]}" -gt 0 ]]; then
|
# Make themes a unique array
|
||||||
themes=($ZSH/themes/${^ZSH_THEME_RANDOM_CANDIDATES}.zsh-theme)
|
typeset -Ua themes
|
||||||
|
|
||||||
|
if [[ "${(t)ZSH_THEME_RANDOM_CANDIDATES}" = array && ${#ZSH_THEME_RANDOM_CANDIDATES[@]} -gt 0 ]]; then
|
||||||
|
# Use ZSH_THEME_RANDOM_CANDIDATES if properly defined
|
||||||
|
themes=($ZSH_THEME_RANDOM_CANDIDATES)
|
||||||
else
|
else
|
||||||
themes=($ZSH/themes/*zsh-theme)
|
# Look for themes in $ZSH_CUSTOM and $ZSH and add only the theme name (:t)
|
||||||
|
themes=(
|
||||||
|
"$ZSH_CUSTOM"/*.zsh-theme(N:t:r)
|
||||||
|
"$ZSH_CUSTOM"/themes/*.zsh-theme(N:t:r)
|
||||||
|
"$ZSH"/themes/*.zsh-theme(N:t:r)
|
||||||
|
)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Choose a theme out of the pool of candidates
|
||||||
N=${#themes[@]}
|
N=${#themes[@]}
|
||||||
(( N = (RANDOM%N) + 1 ))
|
(( N = (RANDOM%N) + 1 ))
|
||||||
RANDOM_THEME=${themes[$N]}
|
RANDOM_THEME="${themes[$N]}"
|
||||||
source "$RANDOM_THEME"
|
unset N themes
|
||||||
echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
|
|
||||||
|
# Source theme
|
||||||
|
if [[ -f "$ZSH_CUSTOM/$RANDOM_THEME.zsh-theme" ]]; then
|
||||||
|
source "$ZSH_CUSTOM/$RANDOM_THEME.zsh-theme"
|
||||||
|
elif [[ -f "$ZSH_CUSTOM/themes/$RANDOM_THEME.zsh-theme" ]]; then
|
||||||
|
source "$ZSH_CUSTOM/themes/$RANDOM_THEME.zsh-theme"
|
||||||
|
elif [[ -f "$ZSH/themes/$RANDOM_THEME.zsh-theme" ]]; then
|
||||||
|
source "$ZSH/themes/$RANDOM_THEME.zsh-theme"
|
||||||
|
else
|
||||||
|
echo "[oh-my-zsh] Random theme '${RANDOM_THEME}' not found"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[oh-my-zsh] Random theme '${RANDOM_THEME}' loaded"
|
||||||
|
|
Loading…
Reference in a new issue