Browse Source

fix(core): move plugin-generated completion files to `$ZSH_CACHE_DIR/completions`

Fixes #10183
Marc Cornellà 2 years ago
parent
commit
d2269180b0

+ 4 - 0
oh-my-zsh.sh

@@ -7,6 +7,10 @@ if [[ -z "$ZSH_CACHE_DIR" ]]; then
   ZSH_CACHE_DIR="$ZSH/cache"
 fi
 
+# Create completions cache dir and add to $fpath
+mkdir -p "$ZSH_CACHE_DIR/completions"
+(( ${fpath[(Ie)$ZSH_CACHE_DIR/completions]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
+
 # Check for updates on initial load...
 if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
   source $ZSH/tools/check_for_upgrade.sh

+ 4 - 1
plugins/cargo/cargo.plugin.zsh

@@ -1,7 +1,10 @@
 if (( $+commands[rustup] && $+commands[cargo] )); then
   ver="$(cargo --version)"
   ver_file="$ZSH_CACHE_DIR/cargo_version"
-  comp_file="$ZSH/plugins/cargo/_cargo"
+  comp_file="$ZSH_CACHE_DIR/completions/_cargo"
+
+  mkdir -p "${comp_file:h}"
+  (( ${fpath[(Ie)${comp_file:h}]} )) || fpath=("${comp_file:h}" $fpath)
 
   if [[ ! -f "$comp_file" || ! -f "$ver_file" || "$ver" != "$(< "$ver_file")" ]]; then
     rustup completions zsh cargo >| "$comp_file"

+ 4 - 1
plugins/deno/deno.plugin.zsh

@@ -14,7 +14,10 @@ alias dup='deno upgrade'
 if (( $+commands[deno] )); then
   ver="$(deno --version)"
   ver_file="$ZSH_CACHE_DIR/deno_version"
-  comp_file="$ZSH/plugins/deno/_deno"
+  comp_file="$ZSH_CACHE_DIR/completions/_deno"
+
+  mkdir -p "${comp_file:h}"
+  (( ${fpath[(Ie)${comp_file:h}]} )) || fpath=("${comp_file:h}" $fpath)
 
   if [[ ! -f "$comp_file" || ! -f "$ver_file" || "$ver" != "$(< "$ver_file")" ]]; then
     deno completions zsh >| "$comp_file"

+ 4 - 1
plugins/fnm/fnm.plugin.zsh

@@ -1,7 +1,10 @@
 if (( $+commands[fnm] )); then
   ver="$(fnm --version)"
   ver_file="$ZSH_CACHE_DIR/fnm_version"
-  comp_file="$ZSH/plugins/fnm/_fnm"
+  comp_file="$ZSH_CACHE_DIR/completions/_fnm"
+
+  mkdir -p "${comp_file:h}"
+  (( ${fpath[(Ie)${comp_file:h}]} )) || fpath=("${comp_file:h}" $fpath)
 
   if [[ ! -f "$comp_file" || ! -f "$ver_file" || "$ver" != "$(< "$ver_file")" ]]; then
     fnm completions --shell=zsh >| "$comp_file"

+ 4 - 1
plugins/gh/gh.plugin.zsh

@@ -2,7 +2,10 @@
 if (( $+commands[gh] )); then
   ver="$(gh --version)"
   ver_file="$ZSH_CACHE_DIR/gh_version"
-  comp_file="$ZSH/plugins/gh/_gh"
+  comp_file="$ZSH_CACHE_DIR/completions/_gh"
+
+  mkdir -p "${comp_file:h}"
+  (( ${fpath[(Ie)${comp_file:h}]} )) || fpath=("${comp_file:h}" $fpath)
 
   if [[ ! -f "$comp_file" || ! -f "$ver_file" || "$ver" != "$(< "$ver_file")" ]]; then
     gh completion --shell zsh >| "$comp_file"

+ 4 - 1
plugins/rustup/rustup.plugin.zsh

@@ -1,7 +1,10 @@
 if (( $+commands[rustup] )); then
   ver="$(rustup --version 2>/dev/null)"
   ver_file="$ZSH_CACHE_DIR/rustup_version"
-  comp_file="$ZSH/plugins/rustup/_rustup"
+  comp_file="$ZSH_CACHE_DIR/completions/_rustup"
+
+  mkdir -p "${comp_file:h}"
+  (( ${fpath[(Ie)${comp_file:h}]} )) || fpath=("${comp_file:h}" $fpath)
 
   if [[ ! -f "$comp_file" || ! -f "$ver_file" || "$ver" != "$(< "$ver_file")" ]]; then
     rustup completions zsh >| "$comp_file"