summaryrefslogtreecommitdiff
path: root/plugins/kubectl/kubectl.plugin.zsh
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2023-01-17 12:46:15 +0100
committerTuowen Zhao <ztuowen@gmail.com>2023-01-17 12:46:15 +0100
commitdb7efd2336e4dbe6abf321b00dbc11bc5afb1355 (patch)
tree720a58ff82bf0a0e0167594131f872d453b1828e /plugins/kubectl/kubectl.plugin.zsh
parent04b8c052e5b624873b352889423c753ed1baf9c4 (diff)
parent8f0e296dbf27026ea0515ebae0d3cc41f236ecdc (diff)
downloadzsh-db7efd2336e4dbe6abf321b00dbc11bc5afb1355.tar.gz
zsh-db7efd2336e4dbe6abf321b00dbc11bc5afb1355.tar.bz2
zsh-db7efd2336e4dbe6abf321b00dbc11bc5afb1355.zip
Merge remote-tracking branch 'github/master'
Diffstat (limited to 'plugins/kubectl/kubectl.plugin.zsh')
-rw-r--r--plugins/kubectl/kubectl.plugin.zsh22
1 files changed, 12 insertions, 10 deletions
diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh
index 095d2b328..315d3ce93 100644
--- a/plugins/kubectl/kubectl.plugin.zsh
+++ b/plugins/kubectl/kubectl.plugin.zsh
@@ -1,15 +1,17 @@
-if (( $+commands[kubectl] )); then
- # If the completion file does not exist, generate it and then source it
- # Otherwise, source it and regenerate in the background
- if [[ ! -f "$ZSH_CACHE_DIR/completions/_kubectl" ]]; then
- kubectl completion zsh | tee "$ZSH_CACHE_DIR/completions/_kubectl" >/dev/null
- source "$ZSH_CACHE_DIR/completions/_kubectl"
- else
- source "$ZSH_CACHE_DIR/completions/_kubectl"
- kubectl completion zsh | tee "$ZSH_CACHE_DIR/completions/_kubectl" >/dev/null &|
- fi
+if (( ! $+commands[kubectl] )); then
+ return
fi
+# If the completion file doesn't exist yet, we need to autoload it and
+# bind it to `kubectl`. Otherwise, compinit will have already done that.
+if [[ ! -f "$ZSH_CACHE_DIR/completions/_kubectl" ]]; then
+ typeset -g -A _comps
+ autoload -Uz _kubectl
+ _comps[kubectl]=_kubectl
+fi
+
+kubectl completion zsh 2> /dev/null >| "$ZSH_CACHE_DIR/completions/_kubectl" &|
+
# This command is used a LOT both below and in daily life
alias k=kubectl