oh-my-zsh.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. : ${ZSH_DISABLE_COMPFIX:=true}
  11. # Set ZSH_CUSTOM to the path where your custom config files
  12. # and plugins exists, or else we will use the default custom/
  13. if [[ -z "$ZSH_CUSTOM" ]]; then
  14. ZSH_CUSTOM="$ZSH/custom"
  15. fi
  16. # Set ZSH_CACHE_DIR to the path where cache files should be created
  17. # or else we will use the default cache/
  18. if [[ -z "$ZSH_CACHE_DIR" ]]; then
  19. ZSH_CACHE_DIR="$ZSH/cache"
  20. fi
  21. # Load all of the config files in ~/oh-my-zsh that end in .zsh
  22. # TIP: Add files you don't want in git to .gitignore
  23. for config_file ($ZSH/lib/*.zsh); do
  24. custom_config_file="${ZSH_CUSTOM}/lib/${config_file:t}"
  25. [ -f "${custom_config_file}" ] && config_file=${custom_config_file}
  26. source $config_file
  27. done
  28. is_plugin() {
  29. local base_dir=$1
  30. local name=$2
  31. test -f $base_dir/plugins/$name/$name.plugin.zsh \
  32. || test -f $base_dir/plugins/$name/_$name
  33. }
  34. # Add all defined plugins to fpath. This must be done
  35. # before running compinit.
  36. for plugin ($plugins); do
  37. if is_plugin $ZSH_CUSTOM $plugin; then
  38. fpath=($ZSH_CUSTOM/plugins/$plugin $fpath)
  39. elif is_plugin $ZSH $plugin; then
  40. fpath=($ZSH/plugins/$plugin $fpath)
  41. fi
  42. done
  43. # Figure out the SHORT hostname
  44. if [[ "$OSTYPE" = darwin* ]]; then
  45. # OS X's $HOST changes with dhcp, etc. Use ComputerName if possible.
  46. SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*/}
  47. else
  48. SHORT_HOST=${HOST/.*/}
  49. fi
  50. # Save the location of the current completion dump file.
  51. if [ -z "$ZSH_COMPDUMP" ]; then
  52. ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
  53. fi
  54. if [[ $ZSH_DISABLE_COMPFIX != true ]]; then
  55. # If completion insecurities exist, warn the user without enabling completions.
  56. if ! compaudit &>/dev/null; then
  57. # This function resides in the "lib/compfix.zsh" script sourced above.
  58. handle_completion_insecurities
  59. # Else, enable and cache completions to the desired file.
  60. else
  61. compinit -d "${ZSH_COMPDUMP}"
  62. fi
  63. else
  64. compinit -i -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. fi
  73. done
  74. # Load all of your custom configurations from custom/
  75. for config_file ($ZSH_CUSTOM/*.zsh(N)); do
  76. source $config_file
  77. done
  78. unset config_file
  79. # Load the theme
  80. if [ "$ZSH_THEME" = "random" ]; then
  81. themes=($ZSH/themes/*zsh-theme)
  82. N=${#themes[@]}
  83. ((N=(RANDOM%N)+1))
  84. RANDOM_THEME=${themes[$N]}
  85. source "$RANDOM_THEME"
  86. echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
  87. else
  88. if [ ! "$ZSH_THEME" = "" ]; then
  89. if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
  90. source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
  91. elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
  92. source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
  93. else
  94. source "$ZSH/themes/$ZSH_THEME.zsh-theme"
  95. fi
  96. fi
  97. fi