4e6e49652b69557c01ef1ce81c96da7eb9b34e6e

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

Message

fix(plugins): fix `_comps` error in completion generation plugins (#10190)

Fixes #10190

Diff

  1diff --git a/plugins/cargo/cargo.plugin.zsh b/plugins/cargo/cargo.plugin.zsh
  2index 92eae535993494cbba5196c4089bd94e070e0880..b636d492fd0c59670a8d307427f09c74b1f56f0b 100644
  3--- a/plugins/cargo/cargo.plugin.zsh
  4+++ b/plugins/cargo/cargo.plugin.zsh
  5@@ -1,11 +1,16 @@
  6-# COMPLETION FUNCTION
  7 if (( $+commands[rustup] && $+commands[cargo] )); then
  8-  if [[ ! -f $ZSH_CACHE_DIR/cargo_version ]] \
  9-    || [[ "$(cargo --version)" != "$(< "$ZSH_CACHE_DIR/cargo_version")" ]] \
 10-    || [[ ! -f $ZSH/plugins/cargo/_cargo ]]; then
 11-    rustup completions zsh cargo > $ZSH/plugins/cargo/_cargo
 12-    cargo --version > $ZSH_CACHE_DIR/cargo_version
 13+  ver="$(cargo --version)"
 14+  ver_file="$ZSH_CACHE_DIR/cargo_version"
 15+  comp_file="$ZSH/plugins/cargo/_cargo"
 16+
 17+  if [[ ! -f "$comp_file" || ! -f "$ver_file" || "$ver" != "$(< "$ver_file")" ]]; then
 18+    rustup completions zsh cargo >| "$comp_file"
 19+    echo "$ver" >| "$ver_file"
 20   fi
 21+
 22+  declare -A _comps
 23   autoload -Uz _cargo
 24   _comps[cargo]=_cargo
 25+
 26+  unset ver ver_file comp_file
 27 fi
 28diff --git a/plugins/deno/deno.plugin.zsh b/plugins/deno/deno.plugin.zsh
 29index a37b3bec4a071aef8f8f990010c4e15ef44faf78..71749f4a0e04e4180901d74e94516dda7c5c806b 100644
 30--- a/plugins/deno/deno.plugin.zsh
 31+++ b/plugins/deno/deno.plugin.zsh
 32@@ -12,12 +12,18 @@ alias dup='deno upgrade'
 33 
 34 # COMPLETION FUNCTION
 35 if (( $+commands[deno] )); then
 36-  if [[ ! -f $ZSH_CACHE_DIR/deno_version ]] \
 37-    || [[ "$(deno --version)" != "$(< "$ZSH_CACHE_DIR/deno_version")" ]] \
 38-    || [[ ! -f $ZSH/plugins/deno/_deno ]]; then
 39-    deno completions zsh > $ZSH/plugins/deno/_deno
 40-    deno --version > $ZSH_CACHE_DIR/deno_version
 41+  ver="$(deno --version)"
 42+  ver_file="$ZSH_CACHE_DIR/deno_version"
 43+  comp_file="$ZSH/plugins/deno/_deno"
 44+
 45+  if [[ ! -f "$comp_file" || ! -f "$ver_file" || "$ver" != "$(< "$ver_file")" ]]; then
 46+    deno completions zsh >| "$comp_file"
 47+    echo "$ver" >| "$ver_file"
 48   fi
 49+
 50+  declare -A _comps
 51   autoload -Uz _deno
 52   _comps[deno]=_deno
 53+
 54+  unset ver ver_file comp_file
 55 fi
 56diff --git a/plugins/fnm/fnm.plugin.zsh b/plugins/fnm/fnm.plugin.zsh
 57index 5ce558dcb4a0ff01e80d3c2bb9ce12c082dbf790..29b759abb71aac1fc5406e74188232ea4e234fd3 100644
 58--- a/plugins/fnm/fnm.plugin.zsh
 59+++ b/plugins/fnm/fnm.plugin.zsh
 60@@ -1,12 +1,17 @@
 61-# COMPLETION FUNCTION
 62 if (( $+commands[fnm] )); then
 63-  if [[ ! -f $ZSH_CACHE_DIR/fnm_version ]] \
 64-    || [[ "$(fnm --version)" != "$(< "$ZSH_CACHE_DIR/fnm_version")" ]] \
 65-    || [[ ! -f $ZSH/plugins/fnm/_fnm ]]; then
 66-      fnm completions --shell=zsh > $ZSH/plugins/fnm/_fnm
 67-      fnm --version > $ZSH_CACHE_DIR/fnm_version
 68+  ver="$(fnm --version)"
 69+  ver_file="$ZSH_CACHE_DIR/fnm_version"
 70+  comp_file="$ZSH/plugins/fnm/_fnm"
 71+
 72+  if [[ ! -f "$comp_file" || ! -f "$ver_file" || "$ver" != "$(< "$ver_file")" ]]; then
 73+    fnm completions --shell=zsh >| "$comp_file"
 74+    echo "$ver" >| "$ver_file"
 75   fi
 76+
 77+  declare -A _comps
 78   autoload -Uz _fnm
 79   _comps[fnm]=_fnm
 80+
 81+  unset ver ver_file comp_file
 82 fi
 83 
 84diff --git a/plugins/gh/gh.plugin.zsh b/plugins/gh/gh.plugin.zsh
 85index 8e055ec3535170e53417a68e01dc0d9e0fc2e93d..c3d87848d72a9fb1276b11977c330cbf840d2aaf 100644
 86--- a/plugins/gh/gh.plugin.zsh
 87+++ b/plugins/gh/gh.plugin.zsh
 88@@ -1,13 +1,18 @@
 89 # Autocompletion for the GitHub CLI (gh).
 90-
 91 if (( $+commands[gh] )); then
 92-  if [[ ! -r "$ZSH_CACHE_DIR/gh_version" \
 93-    || "$(gh --version)" != "$(< "$ZSH_CACHE_DIR/gh_version")"
 94-    || ! -f "$ZSH/plugins/gh/_gh" ]]; then
 95-    gh completion --shell zsh > $ZSH/plugins/gh/_gh
 96-    gh --version > $ZSH_CACHE_DIR/gh_version
 97+  ver="$(gh --version)"
 98+  ver_file="$ZSH_CACHE_DIR/gh_version"
 99+  comp_file="$ZSH/plugins/gh/_gh"
100+
101+  if [[ ! -f "$comp_file" || ! -f "$ver_file" || "$ver" != "$(< "$ver_file")" ]]; then
102+    gh completion --shell zsh >| "$comp_file"
103+    echo "$ver" >| "$ver_file"
104   fi
105+
106+  declare -A _comps
107   autoload -Uz _gh
108   _comps[gh]=_gh
109+
110+  unset ver ver_file comp_file
111 fi
112 
113diff --git a/plugins/rustup/rustup.plugin.zsh b/plugins/rustup/rustup.plugin.zsh
114index c7a9b3060ff9a9a5eb064d8dd3d224840267fabd..e709f41bd3ea60f9dc969b852f7f657e41dc3669 100644
115--- a/plugins/rustup/rustup.plugin.zsh
116+++ b/plugins/rustup/rustup.plugin.zsh
117@@ -1,12 +1,16 @@
118-# COMPLETION FUNCTION
119 if (( $+commands[rustup] )); then
120-  if [[ ! -f $ZSH_CACHE_DIR/rustup_version ]] \
121-    || [[ "$(rustup --version 2> /dev/null)" \
122-      != "$(< "$ZSH_CACHE_DIR/rustup_version")" ]] \
123-    || [[ ! -f $ZSH/plugins/rustup/_rustup ]]; then
124-    rustup completions zsh > $ZSH/plugins/rustup/_rustup
125-    rustup --version 2> /dev/null > $ZSH_CACHE_DIR/rustup_version
126+  ver="$(rustup --version 2>/dev/null)"
127+  ver_file="$ZSH_CACHE_DIR/rustup_version"
128+  comp_file="$ZSH/plugins/rustup/_rustup"
129+
130+  if [[ ! -f "$comp_file" || ! -f "$ver_file" || "$ver" != "$(< "$ver_file")" ]]; then
131+    rustup completions zsh >| "$comp_file"
132+    echo "$ver" >| "$ver_file"
133   fi
134+
135+  declare -A _comps
136   autoload -Uz _rustup
137   _comps[rustup]=_rustup
138+
139+  unset ver ver_file comp_file
140 fi