summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Cornellà <hello@mcornella.com>2023-09-04 19:32:38 +0200
committerGitHub <noreply@github.com>2023-09-04 19:32:38 +0200
commit30f0d591881713c4efd1482511943abca5103927 (patch)
tree8c3eaf13c60de9bd10c51ac0446a8fb416c622c8
parent1abc1d998a71efd50af30210e26bee462496e442 (diff)
downloadzsh-30f0d591881713c4efd1482511943abca5103927.tar.gz
zsh-30f0d591881713c4efd1482511943abca5103927.tar.bz2
zsh-30f0d591881713c4efd1482511943abca5103927.zip
fix(init): exit gracefully if on non-zsh emulation mode (#11874)
Fixes #11686
-rw-r--r--oh-my-zsh.sh27
1 files changed, 18 insertions, 9 deletions
diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh
index 40f13f37e..137ca3b6f 100644
--- a/oh-my-zsh.sh
+++ b/oh-my-zsh.sh
@@ -1,14 +1,14 @@
+# 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() { :; }
+
# 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"
@@ -38,6 +38,15 @@
return 1
}
+# Check if in emulation mode, if so early return
+# https://github.com/ohmyzsh/ohmyzsh/issues/11686
+[[ "$(emulate)" = zsh ]] || {
+ 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
+ return 1
+}
+
+unset -f omz_f
+
# If ZSH is not defined, use the current script's directory.
[[ -z "$ZSH" ]] && export ZSH="${${(%):-%x}:a:h}"