oh-my-zsh.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # Check for updates on initial load...
  2. if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
  3. env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f $ZSH/tools/check_for_upgrade.sh
  4. fi
  5. # Initializes Oh My Zsh
  6. # add a function path
  7. fpath=($ZSH/functions $ZSH/completions $fpath)
  8. # Load all stock functions (from $fpath files) called below.
  9. autoload -U compaudit compinit
  10. # Set ZSH_CUSTOM to the path where your custom config files
  11. # and plugins exists, or else we will use the default custom/
  12. if [[ -z "$ZSH_CUSTOM" ]]; then
  13. ZSH_CUSTOM="$ZSH/custom"
  14. fi
  15. # Set ZSH_CACHE_DIR to the path where cache files should be created
  16. # or else we will use the default cache/
  17. if [[ -z "$ZSH_CACHE_DIR" ]]; then
  18. ZSH_CACHE_DIR="$ZSH/cache"
  19. fi
  20. # Load all of the config files in ~/oh-my-zsh that end in .zsh
  21. # TIP: Add files you don't want in git to .gitignore
  22. for config_file ($ZSH/lib/*.zsh); do
  23. custom_config_file="${ZSH_CUSTOM}/lib/${config_file:t}"
  24. [ -f "${custom_config_file}" ] && config_file=${custom_config_file}
  25. source $config_file
  26. done
  27. is_plugin() {
  28. local base_dir=$1
  29. local name=$2
  30. test -f $base_dir/plugins/$name/$name.plugin.zsh \
  31. || test -f $base_dir/plugins/$name/_$name
  32. }
  33. # Add all defined plugins to fpath. This must be done
  34. # before running compinit.
  35. for plugin ($plugins); do
  36. if is_plugin $ZSH_CUSTOM $plugin; then
  37. fpath=($ZSH_CUSTOM/plugins/$plugin $fpath)
  38. elif is_plugin $ZSH $plugin; then
  39. fpath=($ZSH/plugins/$plugin $fpath)
  40. fi
  41. done
  42. # Figure out the SHORT hostname
  43. if [[ "$OSTYPE" = darwin* ]]; then
  44. # macOS's $HOST changes with dhcp, etc. Use ComputerName if possible.
  45. SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*/}
  46. else
  47. SHORT_HOST=${HOST/.*/}
  48. fi
  49. # Save the location of the current completion dump file.
  50. if [ -z "$ZSH_COMPDUMP" ]; then
  51. ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
  52. fi
  53. if [[ $ZSH_DISABLE_COMPFIX != true ]]; then
  54. # If completion insecurities exist, warn the user
  55. if ! compaudit &>/dev/null; then
  56. handle_completion_insecurities
  57. fi
  58. # Load only from secure directories
  59. compinit -i -d "${ZSH_COMPDUMP}"
  60. else
  61. # If the user wants it, load from all found directories
  62. compinit -u -d "${ZSH_COMPDUMP}"
  63. fi
  64. # Load all of the plugins that were defined in ~/.zshrc
  65. for plugin ($plugins); do
  66. if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then
  67. source $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh
  68. elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then
  69. source $ZSH/plugins/$plugin/$plugin.plugin.zsh
  70. fi
  71. done
  72. # Load all of your custom configurations from custom/
  73. for config_file ($ZSH_CUSTOM/*.zsh(N)); do
  74. source $config_file
  75. done
  76. unset config_file
  77. # Load the theme
  78. if [[ "$ZSH_THEME" == "random" ]]; then
  79. if [[ "${(t)ZSH_THEME_RANDOM_CANDIDATES}" = "array" ]] && [[ "${#ZSH_THEME_RANDOM_CANDIDATES[@]}" -gt 0 ]]; then
  80. themes=($ZSH/themes/${^ZSH_THEME_RANDOM_CANDIDATES}.zsh-theme)
  81. else
  82. themes=($ZSH/themes/*zsh-theme)
  83. fi
  84. N=${#themes[@]}
  85. ((N=(RANDOM%N)+1))
  86. RANDOM_THEME=${themes[$N]}
  87. source "$RANDOM_THEME"
  88. echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
  89. else
  90. if [ ! "$ZSH_THEME" = "" ]; then
  91. if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
  92. source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
  93. elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
  94. source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
  95. else
  96. source "$ZSH/themes/$ZSH_THEME.zsh-theme"
  97. fi
  98. fi
  99. fi