random.zsh-theme 1.21 KB
Newer Older
1
2
3
4
5
# 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
6
  themes=(${(@)ZSH_THEME_RANDOM_CANDIDATES:#random})
7
else
8
  # Look for themes in $ZSH_CUSTOM and $ZSH and add only the theme name
9
10
11
12
13
  themes=(
    "$ZSH_CUSTOM"/*.zsh-theme(N:t:r)
    "$ZSH_CUSTOM"/themes/*.zsh-theme(N:t:r)
    "$ZSH"/themes/*.zsh-theme(N:t:r)
  )
14
  # Remove blacklisted themes from the list
15
  for theme in random ${ZSH_THEME_RANDOM_BLACKLIST[@]}; do
16
17
    themes=("${(@)themes:#$theme}")
  done
18
fi
19
20

# Choose a theme out of the pool of candidates
21
N=${#themes[@]}
22
23
(( N = (RANDOM%N) + 1 ))
RANDOM_THEME="${themes[$N]}"
24
unset N themes theme
25
26
27
28
29
30
31
32
33
34
35
36
37
38

# 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"