summaryrefslogtreecommitdiff
path: root/oh-my-zsh.sh
diff options
context:
space:
mode:
Diffstat (limited to 'oh-my-zsh.sh')
-rw-r--r--oh-my-zsh.sh55
1 files changed, 51 insertions, 4 deletions
diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh
index 4025f0025..b388b341d 100644
--- a/oh-my-zsh.sh
+++ b/oh-my-zsh.sh
@@ -1,17 +1,64 @@
+# Protect against non-zsh execution of Oh My Zsh (use POSIX syntax here)
+[ -n "$ZSH_VERSION" ] || {
+ # ANSI formatting function (\033[<code>m)
+ # 0: reset, 1: bold, 4: underline, 22: no bold, 24: no underline, 31: red, 33: yellow
+ omz_f() {
+ [ $# -gt 0 ] || return
+ IFS=";" printf "\033[%sm" $*
+ }
+ # If stdout is not a terminal ignore all formatting
+ [ -t 1 ] || omz_f() { :; }
+
+ omz_ptree() {
+ # Get process tree of the current process
+ pid=$$; pids="$pid"
+ while [ ${pid-0} -ne 1 ] && ppid=$(ps -e -o pid,ppid | awk "\$1 == $pid { print \$2 }"); do
+ pids="$pids $pid"; pid=$ppid
+ done
+
+ # Show process tree
+ case "$(uname)" in
+ Linux) ps -o ppid,pid,command -f -p $pids 2>/dev/null ;;
+ Darwin|*) ps -o ppid,pid,command -p $pids 2>/dev/null ;;
+ esac
+
+ # If ps command failed, try Busybox ps
+ [ $? -eq 0 ] || ps -o ppid,pid,comm | awk "NR == 1 || index(\"$pids\", \$2) != 0"
+ }
+
+ {
+ shell=$(ps -o pid,comm | awk "\$1 == $$ { print \$2 }")
+ printf "$(omz_f 1 31)Error:$(omz_f 22) Oh My Zsh can't be loaded from: $(omz_f 1)${shell}$(omz_f 22). "
+ printf "You need to run $(omz_f 1)zsh$(omz_f 22) instead.$(omz_f 0)\n"
+ printf "$(omz_f 33)Here's the process tree:$(omz_f 22)\n\n"
+ omz_ptree
+ printf "$(omz_f 0)\n"
+ } >&2
+
+ return 1
+}
+
+# If ZSH is not defined, use the current script's directory.
+[[ -z "$ZSH" ]] && export ZSH="${${(%):-%x}:a:h}"
+
# Set ZSH_CACHE_DIR to the path where cache files should be created
# or else we will use the default cache/
if [[ -z "$ZSH_CACHE_DIR" ]]; then
ZSH_CACHE_DIR="$ZSH/cache"
fi
-# Migrate .zsh-update file to $ZSH_CACHE_DIR
-if [ -f ~/.zsh-update ] && [ ! -f ${ZSH_CACHE_DIR}/.zsh-update ]; then
- mv ~/.zsh-update ${ZSH_CACHE_DIR}/.zsh-update
+# Make sure $ZSH_CACHE_DIR is writable, otherwise use a directory in $HOME
+if [[ ! -w "$ZSH_CACHE_DIR" ]]; then
+ ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/oh-my-zsh"
fi
+# Create cache and completions dir and add to $fpath
+mkdir -p "$ZSH_CACHE_DIR/completions"
+(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
+
# Check for updates on initial load...
if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
- env ZSH=$ZSH ZSH_CACHE_DIR=$ZSH_CACHE_DIR DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f $ZSH/tools/check_for_upgrade.sh
+ source $ZSH/tools/check_for_upgrade.sh
fi
# Initializes Oh My Zsh