random.zsh-theme 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Deprecate ZSH_THEME_RANDOM_BLACKLIST
  2. if [[ -n "$ZSH_THEME_RANDOM_BLACKLIST" ]]; then
  3. echo '[oh-my-zsh] ZSH_THEME_RANDOM_BLACKLIST is deprecated. Use `ZSH_THEME_RANDOM_IGNORED` instead.'
  4. ZSH_THEME_RANDOM_IGNORED=($ZSH_THEME_RANDOM_BLACKLIST)
  5. unset ZSH_THEME_RANDOM_BLACKLIST
  6. fi
  7. # Make themes a unique array
  8. typeset -Ua themes
  9. if [[ "${(t)ZSH_THEME_RANDOM_CANDIDATES}" = array && ${#ZSH_THEME_RANDOM_CANDIDATES[@]} -gt 0 ]]; then
  10. # Use ZSH_THEME_RANDOM_CANDIDATES if properly defined
  11. themes=(${(@)ZSH_THEME_RANDOM_CANDIDATES:#random})
  12. else
  13. # Look for themes in $ZSH_CUSTOM and $ZSH and add only the theme name
  14. themes=(
  15. "$ZSH_CUSTOM"/*.zsh-theme(N:t:r)
  16. "$ZSH_CUSTOM"/themes/*.zsh-theme(N:t:r)
  17. "$ZSH"/themes/*.zsh-theme(N:t:r)
  18. )
  19. # Remove ignored themes from the list
  20. for theme in random ${ZSH_THEME_RANDOM_IGNORED[@]}; do
  21. themes=("${(@)themes:#$theme}")
  22. done
  23. fi
  24. # Choose a theme out of the pool of candidates
  25. N=${#themes[@]}
  26. (( N = (RANDOM%N) + 1 ))
  27. RANDOM_THEME="${themes[$N]}"
  28. unset N themes theme
  29. # Source theme
  30. if [[ -f "$ZSH_CUSTOM/$RANDOM_THEME.zsh-theme" ]]; then
  31. source "$ZSH_CUSTOM/$RANDOM_THEME.zsh-theme"
  32. elif [[ -f "$ZSH_CUSTOM/themes/$RANDOM_THEME.zsh-theme" ]]; then
  33. source "$ZSH_CUSTOM/themes/$RANDOM_THEME.zsh-theme"
  34. elif [[ -f "$ZSH/themes/$RANDOM_THEME.zsh-theme" ]]; then
  35. source "$ZSH/themes/$RANDOM_THEME.zsh-theme"
  36. else
  37. echo "[oh-my-zsh] Random theme '${RANDOM_THEME}' not found"
  38. return 1
  39. fi
  40. if [[ -z "$ZSH_THEME_RANDOM_QUIET" ]]; then
  41. echo "[oh-my-zsh] Random theme '${RANDOM_THEME}' loaded"
  42. fi