mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-19 21:41:07 +01:00
96e473a1d6
BREAKING CHANGE: For consistency, `ZSH_THEME_RANDOM_QUIET` now needs to be `true` if you want to silence the "Random theme loaded" message in the `random` theme. The wiki specified that 1 or true was valid, while the code just checked whether it was set to any value. Being more strict makes sure that we're consistent with the rest of the Settings. Fixes #10534
47 lines
1.5 KiB
Bash
47 lines
1.5 KiB
Bash
# Deprecate ZSH_THEME_RANDOM_BLACKLIST
|
|
if [[ -n "$ZSH_THEME_RANDOM_BLACKLIST" ]]; then
|
|
echo '[oh-my-zsh] ZSH_THEME_RANDOM_BLACKLIST is deprecated. Use `ZSH_THEME_RANDOM_IGNORED` instead.'
|
|
ZSH_THEME_RANDOM_IGNORED=($ZSH_THEME_RANDOM_BLACKLIST)
|
|
unset ZSH_THEME_RANDOM_BLACKLIST
|
|
fi
|
|
|
|
# Make themes a unique array
|
|
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:#random})
|
|
else
|
|
# Look for themes in $ZSH_CUSTOM and $ZSH and add only the theme name
|
|
themes=(
|
|
"$ZSH_CUSTOM"/*.zsh-theme(N:t:r)
|
|
"$ZSH_CUSTOM"/themes/*.zsh-theme(N:t:r)
|
|
"$ZSH"/themes/*.zsh-theme(N:t:r)
|
|
)
|
|
# Remove ignored themes from the list
|
|
for theme in random ${ZSH_THEME_RANDOM_IGNORED[@]}; do
|
|
themes=("${(@)themes:#$theme}")
|
|
done
|
|
fi
|
|
|
|
# Choose a theme out of the pool of candidates
|
|
N=${#themes[@]}
|
|
(( N = (RANDOM%N) + 1 ))
|
|
RANDOM_THEME="${themes[$N]}"
|
|
unset N themes theme
|
|
|
|
# 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
|
|
|
|
if [[ "$ZSH_THEME_RANDOM_QUIET" = true ]]; then
|
|
echo "[oh-my-zsh] Random theme '${RANDOM_THEME}' loaded"
|
|
fi
|