diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2021-10-23 18:01:40 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2021-10-23 18:01:40 -0600 |
commit | fad92c603be0ff36825cc53bf8c485d4b95c7869 (patch) | |
tree | 407fe826be62a3543b6feab4f3552f58575234de /oh-my-zsh.sh | |
parent | c674485e6b4abe313469900997d893d2940ee843 (diff) | |
parent | f1dd97bb2a9df55fae9b1ca26c829b9f8b290667 (diff) | |
download | zsh-fad92c603be0ff36825cc53bf8c485d4b95c7869.tar.gz zsh-fad92c603be0ff36825cc53bf8c485d4b95c7869.tar.bz2 zsh-fad92c603be0ff36825cc53bf8c485d4b95c7869.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'oh-my-zsh.sh')
-rw-r--r-- | oh-my-zsh.sh | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 545d980f0..b388b341d 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -1,3 +1,43 @@ +# 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}" |