random.zsh-theme 1.2 KB

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