oh-my-zsh.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. is_plugin() {
  25. local base_dir=$1
  26. local name=$2
  27. builtin test -f $base_dir/plugins/$name/$name.plugin.zsh \
  28. || builtin test -f $base_dir/plugins/$name/_$name
  29. }
  30. # Add all defined plugins to fpath. This must be done
  31. # before running compinit.
  32. for plugin ($plugins); do
  33. if is_plugin $ZSH_CUSTOM $plugin; then
  34. fpath=($ZSH_CUSTOM/plugins/$plugin $fpath)
  35. elif is_plugin $ZSH $plugin; then
  36. fpath=($ZSH/plugins/$plugin $fpath)
  37. else
  38. echo "[oh-my-zsh] plugin '$plugin' not found"
  39. fi
  40. done
  41. # Figure out the SHORT hostname
  42. if [[ "$OSTYPE" = darwin* ]]; then
  43. # macOS's $HOST changes with dhcp, etc. Use ComputerName if possible.
  44. SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*/}
  45. else
  46. SHORT_HOST=${HOST/.*/}
  47. fi
  48. # Save the location of the current completion dump file.
  49. if [ -z "$ZSH_COMPDUMP" ]; then
  50. ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
  51. fi
  52. # Construct zcompdump OMZ metadata
  53. zcompdump_revision="#omz revision: $(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)"
  54. zcompdump_fpath="#omz fpath: $fpath"
  55. # Delete the zcompdump file if OMZ zcompdump metadata changed
  56. if ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null \
  57. || ! command grep -q -Fx "$zcompdump_fpath" "$ZSH_COMPDUMP" 2>/dev/null; then
  58. echo zcompdump changed
  59. command rm -f "$ZSH_COMPDUMP"
  60. zcompdump_refresh=1
  61. fi
  62. if [[ $ZSH_DISABLE_COMPFIX != true ]]; then
  63. source $ZSH/lib/compfix.zsh
  64. # If completion insecurities exist, warn the user
  65. handle_completion_insecurities
  66. # Load only from secure directories
  67. compinit -i -C -d "${ZSH_COMPDUMP}"
  68. else
  69. # If the user wants it, load from all found directories
  70. compinit -u -C -d "${ZSH_COMPDUMP}"
  71. fi
  72. # Append zcompdump metadata if missing
  73. if (( $zcompdump_refresh )); then
  74. cat >>| "$ZSH_COMPDUMP" <<EOF
  75. $zcompdump_revision
  76. $zcompdump_fpath
  77. EOF
  78. fi
  79. unset zcompdump_revision zcompdump_fpath zcompdump_refresh
  80. # Load all of the config files in ~/oh-my-zsh that end in .zsh
  81. # TIP: Add files you don't want in git to .gitignore
  82. for config_file ($ZSH/lib/*.zsh); do
  83. custom_config_file="${ZSH_CUSTOM}/lib/${config_file:t}"
  84. [ -f "${custom_config_file}" ] && config_file=${custom_config_file}
  85. source $config_file
  86. done
  87. # Load all of the plugins that were defined in ~/.zshrc
  88. for plugin ($plugins); do
  89. if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then
  90. source $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh
  91. elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then
  92. source $ZSH/plugins/$plugin/$plugin.plugin.zsh
  93. fi
  94. done
  95. # Load all of your custom configurations from custom/
  96. for config_file ($ZSH_CUSTOM/*.zsh(N)); do
  97. source $config_file
  98. done
  99. unset config_file
  100. # Load the theme
  101. if [ ! "$ZSH_THEME" = "" ]; then
  102. if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
  103. source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
  104. elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
  105. source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
  106. else
  107. source "$ZSH/themes/$ZSH_THEME.zsh-theme"
  108. fi
  109. fi