oh-my-zsh.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. # Load all of your custom configurations from custom/
  28. for config_file ($ZSH_CUSTOM/*.zsh(N)); do
  29. source $config_file
  30. done
  31. unset config_file
  32. is_plugin() {
  33. local base_dir=$1
  34. local name=$2
  35. test -f $base_dir/plugins/$name/$name.plugin.zsh \
  36. || test -f $base_dir/plugins/$name/_$name
  37. }
  38. # Add all defined plugins to fpath. This must be done
  39. # before running compinit.
  40. for plugin ($plugins); do
  41. if is_plugin $ZSH_CUSTOM $plugin; then
  42. fpath=($ZSH_CUSTOM/plugins/$plugin $fpath)
  43. elif is_plugin $ZSH $plugin; then
  44. fpath=($ZSH/plugins/$plugin $fpath)
  45. fi
  46. done
  47. # Figure out the SHORT hostname
  48. if [[ "$OSTYPE" = darwin* ]]; then
  49. # OS X's $HOST changes with dhcp, etc. Use ComputerName if possible.
  50. SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*/}
  51. else
  52. SHORT_HOST=${HOST/.*/}
  53. fi
  54. # Save the location of the current completion dump file.
  55. if [ -z "$ZSH_COMPDUMP" ]; then
  56. ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
  57. fi
  58. # If completion insecurities exist, warn the user without enabling completions.
  59. if ! compaudit &>/dev/null; then
  60. # This function resides in the "lib/compfix.zsh" script sourced above.
  61. handle_completion_insecurities
  62. # Else, enable and cache completions to the desired file.
  63. else
  64. compinit -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 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