···11+# ANSI formatting function (\033[<code>m)
22+# 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red, 33: yellow
33+omz_f() {
44+ [ $# -gt 0 ] || return
55+ IFS=";" printf "\033[%sm" $*
66+}
77+# If stdout is not a terminal ignore all formatting
88+[ -t 1 ] || omz_f() { :; }
99+1010+# Protect against non-zsh execution of Oh My Zsh (use POSIX syntax here)
1111+[ -n "$ZSH_VERSION" ] || {
1212+ omz_ptree() {
1313+ # Get process tree of the current process
1414+ pid=$$; pids="$pid"
1515+ while [ ${pid-0} -ne 1 ] && ppid=$(ps -e -o pid,ppid | awk "\$1 == $pid { print \$2 }"); do
1616+ pids="$pids $pid"; pid=$ppid
1717+ done
1818+1919+ # Show process tree
2020+ case "$(uname)" in
2121+ Linux) ps -o ppid,pid,command -f -p $pids 2>/dev/null ;;
2222+ Darwin|*) ps -o ppid,pid,command -p $pids 2>/dev/null ;;
2323+ esac
2424+2525+ # If ps command failed, try Busybox ps
2626+ [ $? -eq 0 ] || ps -o ppid,pid,comm | awk "NR == 1 || index(\"$pids\", \$2) != 0"
2727+ }
2828+2929+ {
3030+ shell=$(ps -o pid,comm | awk "\$1 == $$ { print \$2 }")
3131+ printf "$(omz_f 1 31)Error:$(omz_f 22) Oh My Zsh can't be loaded from: $(omz_f 1)${shell}$(omz_f 22). "
3232+ printf "You need to run $(omz_f 1)zsh$(omz_f 22) instead.$(omz_f 0)\n"
3333+ printf "$(omz_f 33)Here's the process tree:$(omz_f 22)\n\n"
3434+ omz_ptree
3535+ printf "$(omz_f 0)\n"
3636+ } >&2
3737+3838+ return 1
3939+}
4040+4141+# Check if in emulation mode, if so early return
4242+# https://github.com/ohmyzsh/ohmyzsh/issues/11686
4343+[[ "$(emulate)" = zsh ]] || {
4444+ printf "$(omz_f 1 31)Error:$(omz_f 22) Oh My Zsh can't be loaded in \`$(emulate)\` emulation mode.$(omz_f 0)\n" >&2
4545+ return 1
4646+}
4747+4848+unset -f omz_f
4949+5050+# If ZSH is not defined, use the current script's directory.
5151+[[ -n "$ZSH" ]] || export ZSH="${${(%):-%x}:a:h}"
5252+5353+# Set ZSH_CUSTOM to the path where your custom config files
5454+# and plugins exists, or else we will use the default custom/
5555+[[ -n "$ZSH_CUSTOM" ]] || ZSH_CUSTOM="$ZSH/custom"
5656+5757+# Set ZSH_CACHE_DIR to the path where cache files should be created
5858+# or else we will use the default cache/
5959+[[ -n "$ZSH_CACHE_DIR" ]] || ZSH_CACHE_DIR="$ZSH/cache"
6060+6161+# Make sure $ZSH_CACHE_DIR is writable, otherwise use a directory in $HOME
6262+if [[ ! -w "$ZSH_CACHE_DIR" ]]; then
6363+ ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/oh-my-zsh"
6464+fi
6565+6666+# Create cache and completions dir and add to $fpath
6767+mkdir -p "$ZSH_CACHE_DIR/completions"
6868+(( ${fpath[(Ie)$ZSH_CACHE_DIR/completions]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
6969+7070+# Check for updates on initial load...
7171+source "$ZSH/tools/check_for_upgrade.sh"
7272+7373+# Initializes Oh My Zsh
7474+7575+# add a function path
7676+fpath=($ZSH/{functions,completions} $ZSH_CUSTOM/{functions,completions} $fpath)
7777+7878+# Load all stock functions (from $fpath files) called below.
7979+autoload -U compaudit compinit zrecompile
8080+8181+is_plugin() {
8282+ local base_dir=$1
8383+ local name=$2
8484+ builtin test -f $base_dir/plugins/$name/$name.plugin.zsh \
8585+ || builtin test -f $base_dir/plugins/$name/_$name
8686+}
8787+8888+# Add all defined plugins to fpath. This must be done
8989+# before running compinit.
9090+for plugin ($plugins); do
9191+ if is_plugin "$ZSH_CUSTOM" "$plugin"; then
9292+ fpath=("$ZSH_CUSTOM/plugins/$plugin" $fpath)
9393+ elif is_plugin "$ZSH" "$plugin"; then
9494+ fpath=("$ZSH/plugins/$plugin" $fpath)
9595+ else
9696+ echo "[oh-my-zsh] plugin '$plugin' not found"
9797+ fi
9898+done
9999+100100+# Figure out the SHORT hostname
101101+if [[ "$OSTYPE" = darwin* ]]; then
102102+ # macOS's $HOST changes with dhcp, etc. Use LocalHostName if possible.
103103+ SHORT_HOST=$(scutil --get LocalHostName 2>/dev/null) || SHORT_HOST="${HOST/.*/}"
104104+else
105105+ SHORT_HOST="${HOST/.*/}"
106106+fi
107107+108108+# Save the location of the current completion dump file.
109109+if [[ -z "$ZSH_COMPDUMP" ]]; then
110110+ ZSH_COMPDUMP="${ZDOTDIR:-$HOME}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
111111+fi
112112+113113+# Construct zcompdump OMZ metadata
114114+zcompdump_revision="#omz revision: $(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)"
115115+zcompdump_fpath="#omz fpath: $fpath"
116116+117117+# Delete the zcompdump file if OMZ zcompdump metadata changed
118118+if ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null \
119119+ || ! command grep -q -Fx "$zcompdump_fpath" "$ZSH_COMPDUMP" 2>/dev/null; then
120120+ command rm -f "$ZSH_COMPDUMP"
121121+ zcompdump_refresh=1
122122+fi
123123+124124+if [[ "$ZSH_DISABLE_COMPFIX" != true ]]; then
125125+ source "$ZSH/lib/compfix.zsh"
126126+ # Load only from secure directories
127127+ compinit -i -d "$ZSH_COMPDUMP"
128128+ # If completion insecurities exist, warn the user
129129+ handle_completion_insecurities &|
130130+else
131131+ # If the user wants it, load from all found directories
132132+ compinit -u -d "$ZSH_COMPDUMP"
133133+fi
134134+135135+# Append zcompdump metadata if missing
136136+if (( $zcompdump_refresh )) \
137137+ || ! command grep -q -Fx "$zcompdump_revision" "$ZSH_COMPDUMP" 2>/dev/null; then
138138+ # Use `tee` in case the $ZSH_COMPDUMP filename is invalid, to silence the error
139139+ # See https://github.com/ohmyzsh/ohmyzsh/commit/dd1a7269#commitcomment-39003489
140140+ tee -a "$ZSH_COMPDUMP" &>/dev/null <<EOF
141141+142142+$zcompdump_revision
143143+$zcompdump_fpath
144144+EOF
145145+fi
146146+unset zcompdump_revision zcompdump_fpath zcompdump_refresh
147147+148148+# zcompile the completion dump file if the .zwc is older or missing.
149149+if command mkdir "${ZSH_COMPDUMP}.lock" 2>/dev/null; then
150150+ zrecompile -q -p "$ZSH_COMPDUMP"
151151+ command rm -rf "$ZSH_COMPDUMP.zwc.old" "${ZSH_COMPDUMP}.lock"
152152+fi
153153+154154+_omz_source() {
155155+ local context filepath="$1"
156156+157157+ # Construct zstyle context based on path
158158+ case "$filepath" in
159159+ lib/*) context="lib:${filepath:t:r}" ;; # :t = lib_name.zsh, :r = lib_name
160160+ plugins/*) context="plugins:${filepath:h:t}" ;; # :h = plugins/plugin_name, :t = plugin_name
161161+ esac
162162+163163+ local disable_aliases=0
164164+ zstyle -T ":omz:${context}" aliases || disable_aliases=1
165165+166166+ # Back up alias names prior to sourcing
167167+ local -A aliases_pre galiases_pre
168168+ if (( disable_aliases )); then
169169+ aliases_pre=("${(@kv)aliases}")
170170+ galiases_pre=("${(@kv)galiases}")
171171+ fi
172172+173173+ # Source file from $ZSH_CUSTOM if it exists, otherwise from $ZSH
174174+ if [[ -f "$ZSH_CUSTOM/$filepath" ]]; then
175175+ source "$ZSH_CUSTOM/$filepath"
176176+ elif [[ -f "$ZSH/$filepath" ]]; then
177177+ source "$ZSH/$filepath"
178178+ fi
179179+180180+ # Unset all aliases that don't appear in the backed up list of aliases
181181+ if (( disable_aliases )); then
182182+ if (( #aliases_pre )); then
183183+ aliases=("${(@kv)aliases_pre}")
184184+ else
185185+ (( #aliases )) && unalias "${(@k)aliases}"
186186+ fi
187187+ if (( #galiases_pre )); then
188188+ galiases=("${(@kv)galiases_pre}")
189189+ else
190190+ (( #galiases )) && unalias "${(@k)galiases}"
191191+ fi
192192+ fi
193193+}
194194+195195+# Load all of the lib files in ~/.oh-my-zsh/lib that end in .zsh
196196+# TIP: Add files you don't want in git to .gitignore
197197+for lib_file ("$ZSH"/lib/*.zsh); do
198198+ _omz_source "lib/${lib_file:t}"
199199+done
200200+unset lib_file
201201+202202+# Load all of the plugins that were defined in ~/.zshrc
203203+for plugin ($plugins); do
204204+ _omz_source "plugins/$plugin/$plugin.plugin.zsh"
205205+done
206206+unset plugin
207207+208208+# Load all of your custom configurations from custom/
209209+for config_file ("$ZSH_CUSTOM"/*.zsh(N)); do
210210+ source "$config_file"
211211+done
212212+unset config_file
213213+214214+# Load the theme
215215+is_theme() {
216216+ local base_dir=$1
217217+ local name=$2
218218+ builtin test -f $base_dir/$name.zsh-theme
219219+}
220220+221221+if [[ -n "$ZSH_THEME" ]]; then
222222+ if is_theme "$ZSH_CUSTOM" "$ZSH_THEME"; then
223223+ source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
224224+ elif is_theme "$ZSH_CUSTOM/themes" "$ZSH_THEME"; then
225225+ source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
226226+ elif is_theme "$ZSH/themes" "$ZSH_THEME"; then
227227+ source "$ZSH/themes/$ZSH_THEME.zsh-theme"
228228+ else
229229+ echo "[oh-my-zsh] theme '$ZSH_THEME' not found"
230230+ fi
231231+fi
232232+233233+# set completion colors to be the same as `ls`, after theme has been loaded
234234+[[ -z "$LS_COLORS" ]] || zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"