oh-my-zsh.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. # Check for updates on initial load...
  7. source $ZSH/tools/check_for_upgrade.sh
  8. # Initializes Oh My Zsh
  9. # add a function path
  10. fpath=($ZSH/functions $ZSH/completions $fpath)
  11. # Load all stock functions (from $fpath files) called below.
  12. autoload -U compaudit compinit
  13. # Set ZSH_CUSTOM to the path where your custom config files
  14. # and plugins exists, or else we will use the default custom/
  15. if [[ -z "$ZSH_CUSTOM" ]]; then
  16. ZSH_CUSTOM="$ZSH/custom"
  17. fi
  18. is_plugin() {
  19. local base_dir=$1
  20. local name=$2
  21. builtin test -f $base_dir/plugins/$name/$name.plugin.zsh \
  22. || builtin test -f $base_dir/plugins/$name/_$name
  23. }
  24. # Add all defined plugins to fpath. This must be done
  25. # before running compinit.
  26. for plugin ($plugins); do
  27. if is_plugin $ZSH_CUSTOM $plugin; then
  28. fpath=($ZSH_CUSTOM/plugins/$plugin $fpath)
  29. elif is_plugin $ZSH $plugin; then
  30. fpath=($ZSH/plugins/$plugin $fpath)
  31. else
  32. echo "[oh-my-zsh] plugin '$plugin' not found"
  33. fi
  34. done
  35. # Figure out the SHORT hostname
  36. if [[ "$OSTYPE" = darwin* ]]; then
  37. # macOS's $HOST changes with dhcp, etc. Use ComputerName if possible.
  38. SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*/}
  39. else
  40. SHORT_HOST=${HOST/.*/}
  41. fi
  42. # Save the location of the current completion dump file.
  43. if [ -z "$ZSH_COMPDUMP" ]; then
  44. ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
  45. fi
  46. # Construct zcompdump OMZ metadata
  47. zcompdump_revision="#omz revision: $(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)"
  48. zcompdump_fpath="#omz fpath: $fpath"
  49. # Delete the zcompdump file if OMZ zcompdump metadata changed
  50. if ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null \
  51. || ! command grep -q -Fx "$zcompdump_fpath" "$ZSH_COMPDUMP" 2>/dev/null; then
  52. command rm -f "$ZSH_COMPDUMP"
  53. zcompdump_refresh=1
  54. fi
  55. if [[ $ZSH_DISABLE_COMPFIX != true ]]; then
  56. source $ZSH/lib/compfix.zsh
  57. # If completion insecurities exist, warn the user
  58. handle_completion_insecurities
  59. # Load only from secure directories
  60. compinit -i -C -d "${ZSH_COMPDUMP}"
  61. else
  62. # If the user wants it, load from all found directories
  63. compinit -u -C -d "${ZSH_COMPDUMP}"
  64. fi
  65. # Append zcompdump metadata if missing
  66. if (( $zcompdump_refresh )); then
  67. # Use `tee` in case the $ZSH_COMPDUMP filename is invalid, to silence the error
  68. # See https://github.com/ohmyzsh/ohmyzsh/commit/dd1a7269#commitcomment-39003489
  69. tee -a "$ZSH_COMPDUMP" &>/dev/null <<EOF
  70. $zcompdump_revision
  71. $zcompdump_fpath
  72. EOF
  73. fi
  74. unset zcompdump_revision zcompdump_fpath zcompdump_refresh
  75. # Load all of the config files in ~/oh-my-zsh that end in .zsh
  76. # TIP: Add files you don't want in git to .gitignore
  77. for config_file ($ZSH/lib/*.zsh); do
  78. custom_config_file="${ZSH_CUSTOM}/lib/${config_file:t}"
  79. [ -f "${custom_config_file}" ] && config_file=${custom_config_file}
  80. source $config_file
  81. done
  82. # Load all of the plugins that were defined in ~/.zshrc
  83. for plugin ($plugins); do
  84. if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then
  85. source $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh
  86. elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then
  87. source $ZSH/plugins/$plugin/$plugin.plugin.zsh
  88. fi
  89. done
  90. # Load all of your custom configurations from custom/
  91. for config_file ($ZSH_CUSTOM/*.zsh(N)); do
  92. source $config_file
  93. done
  94. unset config_file
  95. # Load the theme
  96. if [ ! "$ZSH_THEME" = "" ]; then
  97. if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
  98. source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
  99. elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
  100. source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
  101. else
  102. source "$ZSH/themes/$ZSH_THEME.zsh-theme"
  103. fi
  104. fi