2020-09-19 01:34:17 +08:00
|
|
|
# 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
|
|
|
|
|
2020-02-20 01:42:05 +08:00
|
|
|
# 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
|
2020-03-03 06:53:43 +08:00
|
|
|
themes=(${(@)ZSH_THEME_RANDOM_CANDIDATES:#random})
|
2014-07-17 12:21:09 +08:00
|
|
|
else
|
2020-02-20 02:53:37 +08:00
|
|
|
# Look for themes in $ZSH_CUSTOM and $ZSH and add only the theme name
|
2020-02-20 01:42:05 +08:00
|
|
|
themes=(
|
|
|
|
"$ZSH_CUSTOM"/*.zsh-theme(N:t:r)
|
|
|
|
"$ZSH_CUSTOM"/themes/*.zsh-theme(N:t:r)
|
|
|
|
"$ZSH"/themes/*.zsh-theme(N:t:r)
|
|
|
|
)
|
2020-09-19 01:34:17 +08:00
|
|
|
# Remove ignored themes from the list
|
|
|
|
for theme in random ${ZSH_THEME_RANDOM_IGNORED[@]}; do
|
2020-02-20 02:53:37 +08:00
|
|
|
themes=("${(@)themes:#$theme}")
|
|
|
|
done
|
2014-07-17 12:21:09 +08:00
|
|
|
fi
|
2020-02-20 01:42:05 +08:00
|
|
|
|
|
|
|
# Choose a theme out of the pool of candidates
|
2014-07-17 12:21:09 +08:00
|
|
|
N=${#themes[@]}
|
2020-02-20 01:42:05 +08:00
|
|
|
(( N = (RANDOM%N) + 1 ))
|
|
|
|
RANDOM_THEME="${themes[$N]}"
|
2020-02-20 02:53:37 +08:00
|
|
|
unset N themes theme
|
2020-02-20 01:42:05 +08:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2021-12-28 18:04:13 +08:00
|
|
|
if [[ "$ZSH_THEME_RANDOM_QUIET" != true ]]; then
|
2020-09-20 19:41:21 +08:00
|
|
|
echo "[oh-my-zsh] Random theme '${RANDOM_THEME}' loaded"
|
|
|
|
fi
|