oh-my-zsh.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. # Load all of your custom configurations from custom/
  26. for config_file ($ZSH_CUSTOM/*.zsh(N)); do
  27. source $config_file
  28. done
  29. unset config_file
  30. is_plugin() {
  31. local base_dir=$1
  32. local name=$2
  33. test -f $base_dir/plugins/$name/$name.plugin.zsh \
  34. || test -f $base_dir/plugins/$name/_$name
  35. }
  36. # Add all defined plugins to fpath. This must be done
  37. # before running compinit.
  38. for plugin ($plugins); do
  39. if is_plugin $ZSH_CUSTOM $plugin; then
  40. fpath=($ZSH_CUSTOM/plugins/$plugin $fpath)
  41. elif is_plugin $ZSH $plugin; then
  42. fpath=($ZSH/plugins/$plugin $fpath)
  43. fi
  44. done
  45. # Figure out the SHORT hostname
  46. if [[ "$OSTYPE" = darwin* ]]; then
  47. # OS X's $HOST changes with dhcp, etc. Use ComputerName if possible.
  48. SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*/}
  49. else
  50. SHORT_HOST=${HOST/.*/}
  51. fi
  52. # Save the location of the current completion dump file.
  53. if [ -z "$ZSH_COMPDUMP" ]; then
  54. ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
  55. fi
  56. # Load and run compinit
  57. autoload -U compinit
  58. compinit -i -d "${ZSH_COMPDUMP}"
  59. # Load all of the plugins that were defined in ~/.zshrc
  60. for plugin ($plugins); do
  61. if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then
  62. source $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh
  63. elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then
  64. source $ZSH/plugins/$plugin/$plugin.plugin.zsh
  65. fi
  66. done
  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