d3bb52d7d825f2a6ce2e1c76ca472b05c6f27b40

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

Message

style: declare globals properly

By default, `typeset` defines variables locally unless in the main scope.
This is specially bad when using `omz plugin load`, which happens inside
a function, so the declared variables don't continue being defined when
the function finishes and the main scope reappears.

Diff

  1diff --git a/plugins/colored-man-pages/colored-man-pages.plugin.zsh b/plugins/colored-man-pages/colored-man-pages.plugin.zsh
  2index 087ddce9785e9dc7e7b4231d57d2edb4717f6923..981992d88e01a9f6484a25b80955bb36590047c8 100644
  3--- a/plugins/colored-man-pages/colored-man-pages.plugin.zsh
  4+++ b/plugins/colored-man-pages/colored-man-pages.plugin.zsh
  5@@ -22,7 +22,7 @@ less_termcap[ue]="${reset_color}"
  6 0="${${(M)0:#/*}:-$PWD/$0}"
  7 
  8 # Absolute path to this file's directory.
  9-typeset __colored_man_pages_dir="${0:A:h}"
 10+typeset -g __colored_man_pages_dir="${0:A:h}"
 11 
 12 function colored() {
 13   local -a environment
 14diff --git a/plugins/deno/deno.plugin.zsh b/plugins/deno/deno.plugin.zsh
 15index 77c2125d25411d76dfe15b106a38247526a2140f..6c12bae13c3ed67c28a7bcd24678455901ffee59 100644
 16--- a/plugins/deno/deno.plugin.zsh
 17+++ b/plugins/deno/deno.plugin.zsh
 18@@ -32,7 +32,7 @@ command mkdir -p "$ZSH_CACHE_DIR/completions"
 19 # If the completion file doesn't exist yet, we need to autoload it and
 20 # bind it to `deno`. Otherwise, compinit will have already done that.
 21 if [[ ! -f "$ZSH_CACHE_DIR/completions/_deno" ]]; then
 22-  declare -A _comps
 23+  typeset -g -A _comps
 24   autoload -Uz _deno
 25   _comps[deno]=_deno
 26 fi
 27diff --git a/plugins/fnm/fnm.plugin.zsh b/plugins/fnm/fnm.plugin.zsh
 28index e225887926c78abdb35f3636420e4eb40598a0fb..044e16a0425d9850c83b1e3f944583ddc9a8e04a 100644
 29--- a/plugins/fnm/fnm.plugin.zsh
 30+++ b/plugins/fnm/fnm.plugin.zsh
 31@@ -18,7 +18,7 @@ command mkdir -p "$ZSH_CACHE_DIR/completions"
 32 # If the completion file doesn't exist yet, we need to autoload it and
 33 # bind it to `fnm`. Otherwise, compinit will have already done that.
 34 if [[ ! -f "$ZSH_CACHE_DIR/completions/_fnm" ]]; then
 35-  declare -A _comps
 36+  typeset -g -A _comps
 37   autoload -Uz _fnm
 38   _comps[fnm]=_fnm
 39 fi
 40diff --git a/plugins/gh/gh.plugin.zsh b/plugins/gh/gh.plugin.zsh
 41index 17995e1cf12c8ba5c0473d2812838ccc9391d968..9263220caa11e357dbb8517993c940046e5fca20 100644
 42--- a/plugins/gh/gh.plugin.zsh
 43+++ b/plugins/gh/gh.plugin.zsh
 44@@ -19,7 +19,7 @@ command mkdir -p "$ZSH_CACHE_DIR/completions"
 45 # If the completion file doesn't exist yet, we need to autoload it and
 46 # bind it to `gh`. Otherwise, compinit will have already done that.
 47 if [[ ! -f "$ZSH_CACHE_DIR/completions/_gh" ]]; then
 48-  declare -A _comps
 49+  typeset -g -A _comps
 50   autoload -Uz _gh
 51   _comps[gh]=_gh
 52 fi
 53diff --git a/plugins/helm/helm.plugin.zsh b/plugins/helm/helm.plugin.zsh
 54index 472c1c9dde025d1263a6912d64c1a8980fceefd4..c6b91693a4c4302bd2cf5d0b028bde88e15f17f2 100644
 55--- a/plugins/helm/helm.plugin.zsh
 56+++ b/plugins/helm/helm.plugin.zsh
 57@@ -14,7 +14,7 @@ command mkdir -p "$ZSH_CACHE_DIR/completions"
 58 # If the completion file doesn't exist yet, we need to autoload it and
 59 # bind it to `helm`. Otherwise, compinit will have already done that.
 60 if [[ ! -f "$ZSH_CACHE_DIR/completions/_helm" ]]; then
 61-  declare -A _comps
 62+  typeset -g -A _comps
 63   autoload -Uz _helm
 64   _comps[helm]=_helm
 65 fi
 66diff --git a/plugins/rbw/rbw.plugin.zsh b/plugins/rbw/rbw.plugin.zsh
 67index 3825be7a64ee717ceea085ea614627902a58f59a..56683ad067dfd507d6589449fce8c9de61c39083 100644
 68--- a/plugins/rbw/rbw.plugin.zsh
 69+++ b/plugins/rbw/rbw.plugin.zsh
 70@@ -11,7 +11,7 @@ command mkdir -p "$ZSH_CACHE_DIR/completions"
 71 # If the completion file doesn't exist yet, we need to autoload it and
 72 # bind it to `rbw`. Otherwise, compinit will have already done that.
 73 if [[ ! -f "$ZSH_CACHE_DIR/completions/_rbw" ]]; then
 74-  declare -A _comps
 75+  typeset -g -A _comps
 76   autoload -Uz _rbw
 77   _comps[rbw]=_rbw
 78 fi
 79diff --git a/plugins/rust/rust.plugin.zsh b/plugins/rust/rust.plugin.zsh
 80index 014c73b3b16756d240c5b2a55c8dddfa78843b67..465b701b03b086d01ee17e33b82cb6aa68212c84 100644
 81--- a/plugins/rust/rust.plugin.zsh
 82+++ b/plugins/rust/rust.plugin.zsh
 83@@ -11,7 +11,7 @@ command mkdir -p "$ZSH_CACHE_DIR/completions"
 84 # bind it to `cargo`. Otherwise, compinit will have already done that
 85 if [[ ! -f "$ZSH_CACHE_DIR/completions/_cargo" ]]; then
 86   autoload -Uz _cargo
 87-  declare -A _comps
 88+  typeset -g -A _comps
 89   _comps[cargo]=_cargo
 90 fi
 91 
 92@@ -19,7 +19,7 @@ fi
 93 # bind it to `rustup`. Otherwise, compinit will have already done that
 94 if [[ ! -f "$ZSH_CACHE_DIR/completions/_rustup" ]]; then
 95   autoload -Uz _rustup
 96-  declare -A _comps
 97+  typeset -g -A _comps
 98   _comps[rustup]=_rustup
 99 fi
100 
101diff --git a/plugins/rvm/rvm.plugin.zsh b/plugins/rvm/rvm.plugin.zsh
102index 4ba8855634bd8763a3ed93e6be3b67270d44a35f..864389ba8d0a88092b96df5784c69c87d7d403c3 100644
103--- a/plugins/rvm/rvm.plugin.zsh
104+++ b/plugins/rvm/rvm.plugin.zsh
105@@ -1,7 +1,7 @@
106 # Completion
107 fpath+=("${rvm_path}/scripts/zsh/Completion")
108 
109-declare -A _comps
110+typeset -g -A _comps
111 autoload -Uz _rvm
112 _comps[rvm]=_rvm
113 
114diff --git a/plugins/volta/volta.plugin.zsh b/plugins/volta/volta.plugin.zsh
115index 756dc84b3901abce45a2fcf80f53b5f8954f6cbe..79319394c329bf5ba3fc934118149d945827e31f 100644
116--- a/plugins/volta/volta.plugin.zsh
117+++ b/plugins/volta/volta.plugin.zsh
118@@ -11,7 +11,7 @@ command mkdir -p "$ZSH_CACHE_DIR/completions"
119 # If the completion file doesn't exist yet, we need to autoload it and
120 # bind it to `deno`. Otherwise, compinit will have already done that.
121 if [[ ! -f "$ZSH_CACHE_DIR/completions/_volta" ]]; then
122-  declare -A _comps
123+  typeset -g -A _comps
124   autoload -Uz _volta
125   _comps[volta]=_volta
126 fi
127diff --git a/themes/dieter.zsh-theme b/themes/dieter.zsh-theme
128index 58d9f88a9c0ed2de78a3b9ab8f769caa6d312db4..83f2dcc7c42310ffa3f89008da35f6aa2e0bef75 100644
129--- a/themes/dieter.zsh-theme
130+++ b/themes/dieter.zsh-theme
131@@ -6,7 +6,7 @@
132 # The exit code visual cues will only display once.
133 # (i.e. they will be reset, even if you hit enter a few times on empty command prompts)
134 
135-typeset -A host_repr
136+typeset -g -A host_repr
137 
138 # translate hostnames into shortened, colorcoded strings
139 host_repr=('dieter-ws-a7n8x-arch' "%{$fg_bold[green]%}ws" 'dieter-p4sci-arch' "%{$fg_bold[blue]%}p4")
140diff --git a/themes/jonathan.zsh-theme b/themes/jonathan.zsh-theme
141index 11d799a84f3072ea048e326e01e57ff2bd721d7d..e8c49088466b53ce36dcc3d8f688754acdcc21f0 100644
142--- a/themes/jonathan.zsh-theme
143+++ b/themes/jonathan.zsh-theme
144@@ -66,7 +66,7 @@ if [[ "${langinfo[CODESET]}" = UTF-8 ]]; then
145   PR_LRCORNER="┘"
146   PR_URCORNER="┐"
147 else
148-  typeset -A altchar
149+  typeset -g -A altchar
150   set -A altchar ${(s..)terminfo[acsc]}
151   # Some stuff to help us draw nice lines
152   PR_SET_CHARSET="%{$terminfo[enacs]%}"