Browse Source

refactor(minikube): standardize completion generation

Closes #10763
Carlo Sala 4 months ago
parent
commit
a9b6af5b23
1 changed files with 11 additions and 11 deletions
  1. 11 11
      plugins/minikube/minikube.plugin.zsh

+ 11 - 11
plugins/minikube/minikube.plugin.zsh

@@ -1,13 +1,13 @@
-# Autocompletion for Minikube.
-#
-if (( $+commands[minikube] )); then
-    __MINIKUBE_COMPLETION_FILE="${ZSH_CACHE_DIR}/minikube_completion"
-
-    if [[ ! -f $__MINIKUBE_COMPLETION_FILE ]]; then
-        minikube completion zsh >! $__MINIKUBE_COMPLETION_FILE
-    fi
-
-    [[ -f $__MINIKUBE_COMPLETION_FILE ]] && source $__MINIKUBE_COMPLETION_FILE
+if (( ! $+commands[minikube] )); then
+  return
+fi
 
-    unset __MINIKUBE_COMPLETION_FILE
+# If the completion file doesn't exist yet, we need to autoload it and
+# bind it to `minikube`. Otherwise, compinit will have already done that.
+if [[ ! -f "$ZSH_CACHE_DIR/completions/_minikube" ]]; then
+  typeset -g -A _comps
+  autoload -Uz _minikube
+  _comps[minikube]=_minikube
 fi
+
+minikube completion zsh >| "$ZSH_CACHE_DIR/completions/_minikube" &|