oh-my-zsh.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. # OS X'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 completion insecurities exist, warn the user without enabling completions.
  54. if ! compaudit &>/dev/null; then
  55. # This function resides in the "lib/compfix.zsh" script sourced above.
  56. handle_completion_insecurities
  57. # Else, enable and cache completions to the desired file.
  58. else
  59. compinit -d "${ZSH_COMPDUMP}"
  60. fi
  61. # Load all of the plugins that were defined in ~/.zshrc
  62. for plugin ($plugins); do
  63. if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then
  64. source $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh
  65. elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then
  66. source $ZSH/plugins/$plugin/$plugin.plugin.zsh
  67. fi
  68. done
  69. # Load all of your custom configurations from custom/
  70. for config_file ($ZSH_CUSTOM/*.zsh(N)); do
  71. source $config_file
  72. done
  73. unset config_file
  74. # Load the theme
  75. if [ "$ZSH_THEME" = "random" ]; then
  76. themes=($ZSH/themes/*zsh-theme)
  77. N=${#themes[@]}
  78. ((N=(RANDOM%N)+1))
  79. RANDOM_THEME=${themes[$N]}
  80. source "$RANDOM_THEME"
  81. echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
  82. else
  83. if [ ! "$ZSH_THEME" = "" ]; then
  84. if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
  85. source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
  86. elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
  87. source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
  88. else
  89. source "$ZSH/themes/$ZSH_THEME.zsh-theme"
  90. fi
  91. fi
  92. fi