oh-my-zsh.sh 2.9 KB

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