1 # Protect against non-zsh execution of Oh My Zsh (use POSIX syntax here)
2 [ -n "$ZSH_VERSION" ] || {
3 # ANSI formatting function (\033[<code>m)
4 # 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red, 33: yellow
7 IFS=";" printf "\033[%sm" $*
9 # If stdout is not a terminal ignore all formatting
10 [ -t 1 ] || omz_f() { :; }
13 # Get process tree of the current process
15 while [ ${pid-0} -ne 1 ] && ppid=$(ps -e -o pid,ppid | awk "\$1 == $pid { print \$2 }"); do
16 pids="$pids $pid"; pid=$ppid
21 Linux) ps -o ppid,pid,command -f -p $pids 2>/dev/null ;;
22 Darwin|*) ps -o ppid,pid,command -p $pids 2>/dev/null ;;
25 # If ps command failed, try Busybox ps
26 [ $? -eq 0 ] || ps -o ppid,pid,comm | awk "NR == 1 || index(\"$pids\", \$2) != 0"
30 shell=$(ps -o pid,comm | awk "\$1 == $$ { print \$2 }")
31 printf "$(omz_f 1 31)Error:$(omz_f 22) Oh My Zsh can't be loaded from: $(omz_f 1)${shell}$(omz_f 22). "
32 printf "You need to run $(omz_f 1)zsh$(omz_f 22) instead.$(omz_f 0)\n"
33 printf "$(omz_f 33)Here's the process tree:$(omz_f 22)\n\n"
41 # If ZSH is not defined, use the current script's directory.
42 [[ -z "$ZSH" ]] && export ZSH="${${(%):-%x}:a:h}"
44 # Set ZSH_CACHE_DIR to the path where cache files should be created
45 # or else we will use the default cache/
46 if [[ -z "$ZSH_CACHE_DIR" ]]; then
47 ZSH_CACHE_DIR="$ZSH/cache"
50 # Make sure $ZSH_CACHE_DIR is writable, otherwise use a directory in $HOME
51 if [[ ! -w "$ZSH_CACHE_DIR" ]]; then
52 ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/oh-my-zsh"
55 # Create cache and completions dir and add to $fpath
56 mkdir -p "$ZSH_CACHE_DIR/completions"
57 (( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
59 # Check for updates on initial load...
60 if [[ "$DISABLE_AUTO_UPDATE" != true ]]; then
61 source "$ZSH/tools/check_for_upgrade.sh"
64 # Initializes Oh My Zsh
67 fpath=("$ZSH/functions" "$ZSH/completions" $fpath)
69 # Load all stock functions (from $fpath files) called below.
70 autoload -U compaudit compinit zrecompile
72 # Set ZSH_CUSTOM to the path where your custom config files
73 # and plugins exists, or else we will use the default custom/
74 if [[ -z "$ZSH_CUSTOM" ]]; then
75 ZSH_CUSTOM="$ZSH/custom"
81 builtin test -f $base_dir/plugins/$name/$name.plugin.zsh \
82 || builtin test -f $base_dir/plugins/$name/_$name
85 # Add all defined plugins to fpath. This must be done
86 # before running compinit.
87 for plugin ($plugins); do
88 if is_plugin "$ZSH_CUSTOM" "$plugin"; then
89 fpath=("$ZSH_CUSTOM/plugins/$plugin" $fpath)
90 elif is_plugin "$ZSH" "$plugin"; then
91 fpath=("$ZSH/plugins/$plugin" $fpath)
93 echo "[oh-my-zsh] plugin '$plugin' not found"
97 # Figure out the SHORT hostname
98 if [[ "$OSTYPE" = darwin* ]]; then
99 # macOS's $HOST changes with dhcp, etc. Use ComputerName if possible.
100 SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST="${HOST/.*/}"
102 SHORT_HOST="${HOST/.*/}"
105 # Save the location of the current completion dump file.
106 if [[ -z "$ZSH_COMPDUMP" ]]; then
107 ZSH_COMPDUMP="${ZDOTDIR:-$HOME}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
110 # Construct zcompdump OMZ metadata
111 zcompdump_revision="#omz revision: $(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)"
112 zcompdump_fpath="#omz fpath: $fpath"
114 # Delete the zcompdump file if OMZ zcompdump metadata changed
115 if ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null \
116 || ! command grep -q -Fx "$zcompdump_fpath" "$ZSH_COMPDUMP" 2>/dev/null; then
117 command rm -f "$ZSH_COMPDUMP"
121 if [[ "$ZSH_DISABLE_COMPFIX" != true ]]; then
122 source "$ZSH/lib/compfix.zsh"
123 # Load only from secure directories
124 compinit -i -d "$ZSH_COMPDUMP"
125 # If completion insecurities exist, warn the user
126 handle_completion_insecurities &|
128 # If the user wants it, load from all found directories
129 compinit -u -d "$ZSH_COMPDUMP"
132 # Append zcompdump metadata if missing
133 if (( $zcompdump_refresh )) \
134 || ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null; then
135 # Use `tee` in case the $ZSH_COMPDUMP filename is invalid, to silence the error
136 # See https://github.com/ohmyzsh/ohmyzsh/commit/dd1a7269#commitcomment-39003489
137 tee -a "$ZSH_COMPDUMP" &>/dev/null <<EOF
143 unset zcompdump_revision zcompdump_fpath zcompdump_refresh
145 # zcompile the completion dump file if the .zwc is older or missing.
146 zrecompile -q -p "$ZSH_COMPDUMP" && command rm -f "$ZSH_COMPDUMP.zwc.old"
148 # Load all of the config files in ~/oh-my-zsh that end in .zsh
149 # TIP: Add files you don't want in git to .gitignore
150 for config_file ("$ZSH"/lib/*.zsh); do
151 custom_config_file="$ZSH_CUSTOM/lib/${config_file:t}"
152 [[ -f "$custom_config_file" ]] && config_file="$custom_config_file"
153 source "$config_file"
155 unset custom_config_file
157 # Load all of the plugins that were defined in ~/.zshrc
158 for plugin ($plugins); do
159 if [[ -f "$ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh" ]]; then
160 source "$ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh"
161 elif [[ -f "$ZSH/plugins/$plugin/$plugin.plugin.zsh" ]]; then
162 source "$ZSH/plugins/$plugin/$plugin.plugin.zsh"
167 # Load all of your custom configurations from custom/
168 for config_file ("$ZSH_CUSTOM"/*.zsh(N)); do
169 source "$config_file"
177 builtin test -f $base_dir/$name.zsh-theme
180 if [[ -n "$ZSH_THEME" ]]; then
181 if is_theme "$ZSH_CUSTOM" "$ZSH_THEME"; then
182 source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
183 elif is_theme "$ZSH_CUSTOM/themes" "$ZSH_THEME"; then
184 source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
185 elif is_theme "$ZSH/themes" "$ZSH_THEME"; then
186 source "$ZSH/themes/$ZSH_THEME.zsh-theme"
188 echo "[oh-my-zsh] theme '$ZSH_THEME' not found"