oh-my-zsh.sh 3.6 KB

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