84931adcd465e9a3b5e38f3b416a1df2acc33801

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

fix: do not call chpwd hooks in subshells

Diff

 1diff --git a/lib/cli.zsh b/lib/cli.zsh
 2index 70076bcfb32c43c7acdcd75df95d582e12052902..2f3f293da99d5644802d182281d128db94a9af91 100644
 3--- a/lib/cli.zsh
 4+++ b/lib/cli.zsh
 5@@ -37,7 +37,7 @@ function _omz {
 6   elif (( CURRENT == 3 )); then
 7     case "$words[2]" in
 8       changelog) local -a refs
 9-        refs=("${(@f)$(cd "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
10+        refs=("${(@f)$(builtin cd -q "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
11         _describe 'command' refs ;;
12       plugin) subcmds=(
13         'disable:Disable plugin(s)'
14@@ -176,7 +176,7 @@ function _omz::changelog {
15   local version=${1:-HEAD} format=${3:-"--text"}
16 
17   if (
18-    cd "$ZSH"
19+    builtin cd -q "$ZSH"
20     ! command git show-ref --verify refs/heads/$version && \
21     ! command git show-ref --verify refs/tags/$version && \
22     ! command git rev-parse --verify "${version}^{commit}"
23@@ -761,7 +761,7 @@ function _omz::theme::use {
24 }
25 
26 function _omz::update {
27-  local last_commit=$(cd "$ZSH"; git rev-parse HEAD)
28+  local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD)
29 
30   # Run update script
31   if [[ "$1" != --unattended ]]; then
32@@ -777,7 +777,7 @@ function _omz::update {
33   command rm -rf "$ZSH/log/update.lock"
34 
35   # Restart the zsh session if there were changes
36-  if [[ "$1" != --unattended && "$(cd "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then
37+  if [[ "$1" != --unattended && "$(builtin cd -q "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then
38     # Old zsh versions don't have ZSH_ARGZERO
39     local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
40     # Check whether to run a login shell
41@@ -787,7 +787,7 @@ function _omz::update {
42 
43 function _omz::version {
44   (
45-    cd "$ZSH"
46+    builtin cd -q "$ZSH"
47 
48     # Get the version name:
49     # 1) try tag-like version
50diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh
51index 729d8ecb5bc131946acd6e548f7f68dc5b2ab1c4..3f6d35c3eed596e6a378e56c7e6c71ee559e66b5 100644
52--- a/tools/check_for_upgrade.sh
53+++ b/tools/check_for_upgrade.sh
54@@ -36,11 +36,11 @@ function current_epoch() {
55 
56 function is_update_available() {
57   local branch
58-  branch=${"$(cd "$ZSH"; git config --local oh-my-zsh.branch)":-master}
59+  branch=${"$(cd -q "$ZSH"; git config --local oh-my-zsh.branch)":-master}
60 
61   local remote remote_url remote_repo
62-  remote=${"$(cd "$ZSH"; git config --local oh-my-zsh.remote)":-origin}
63-  remote_url=$(cd "$ZSH"; git config remote.$remote.url)
64+  remote=${"$(cd -q "$ZSH"; git config --local oh-my-zsh.remote)":-origin}
65+  remote_url=$(cd -q "$ZSH"; git config remote.$remote.url)
66 
67   local repo
68   case "$remote_url" in
69@@ -58,7 +58,7 @@ function is_update_available() {
70 
71   # Get local HEAD. If this fails assume there are updates
72   local local_head
73-  local_head=$(cd "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0
74+  local_head=$(cd -q "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0
75 
76   # Get remote HEAD. If no suitable command is found assume there are updates
77   # On any other error, skip the update (connection may be down)
78@@ -136,7 +136,7 @@ function update_ohmyzsh() {
79   fi
80 
81   # Test if Oh My Zsh directory is a git repository
82-  if ! (cd "$ZSH" && LANG= git rev-parse &>/dev/null); then
83+  if ! (cd -q "$ZSH" && LANG= git rev-parse &>/dev/null); then
84     echo >&2 "[oh-my-zsh] Can't update: not a git repository."
85     return
86   fi