diff --git a/plugins/invoke/invoke.plugin.zsh b/plugins/invoke/invoke.plugin.zsh index 8c807de02..4e8849a15 100644 --- a/plugins/invoke/invoke.plugin.zsh +++ b/plugins/invoke/invoke.plugin.zsh @@ -1,5 +1,18 @@ -# Autocompletion for invoke. -# -if [ $commands[invoke] ]; then - source <(invoke --print-completion-script=zsh) +# Autocompletion for the Invoke CLI (invoke). +if (( ! $+commands[invoke] )); then + return +fi + +# 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/_invoke" ]]; then + invoke --print-completion-script=zsh | tee "$ZSH_CACHE_DIR/completions/_invoke" >/dev/null + source "$ZSH_CACHE_DIR/completions/_invoke" +else + source "$ZSH_CACHE_DIR/completions/_invoke" + zmodload -F zsh/files b:zf_mv + () { + local TMPPREFIX="$ZSH_CACHE_DIR/completions/._invoke" + zf_mv -f -- =( invoke --print-completion-script=zsh ) "$ZSH_CACHE_DIR/completions/_invoke" + } &| fi diff --git a/plugins/istioctl/istioctl.plugin.zsh b/plugins/istioctl/istioctl.plugin.zsh index 13ead1b2b..8c9698e87 100644 --- a/plugins/istioctl/istioctl.plugin.zsh +++ b/plugins/istioctl/istioctl.plugin.zsh @@ -1,4 +1,18 @@ -if [ $commands[istioctl] ]; then - source <(istioctl completion zsh) - compdef _istioctl istioctl +# Autocompletion for the Istio CLI (istioctl). +if (( ! $+commands[istioctl] )); then + return +fi + +# 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/_istioctl" ]]; then + istioctl completion zsh | tee "$ZSH_CACHE_DIR/completions/_istioctl" >/dev/null + source "$ZSH_CACHE_DIR/completions/_istioctl" +else + source "$ZSH_CACHE_DIR/completions/_istioctl" + zmodload -F zsh/files b:zf_mv + () { + local TMPPREFIX="$ZSH_CACHE_DIR/completions/._istioctl" + zf_mv -f -- =( istioctl completion zsh ) "$ZSH_CACHE_DIR/completions/_istioctl" + } &| fi diff --git a/plugins/kn/kn.plugin.zsh b/plugins/kn/kn.plugin.zsh index 483d1d68c..028b2bfa9 100644 --- a/plugins/kn/kn.plugin.zsh +++ b/plugins/kn/kn.plugin.zsh @@ -1,8 +1,21 @@ -# Autocompletion for kn, the command line interface for knative +# Autocompletion for kn, the command line interface for Knative. # # Author: https://github.com/btannous -if [ $commands[kn] ]; then - source <(kn completion zsh) - compdef _kn kn +if (( ! $+commands[kn] )); then + return +fi + +# 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/_kn" ]]; then + kn completion zsh | tee "$ZSH_CACHE_DIR/completions/_kn" >/dev/null + source "$ZSH_CACHE_DIR/completions/_kn" +else + source "$ZSH_CACHE_DIR/completions/_kn" + zmodload -F zsh/files b:zf_mv + () { + local TMPPREFIX="$ZSH_CACHE_DIR/completions/._kn" + zf_mv -f -- =( kn completion zsh ) "$ZSH_CACHE_DIR/completions/_kn" + } &| fi diff --git a/plugins/kompose/kompose.plugin.zsh b/plugins/kompose/kompose.plugin.zsh index 764e724e6..72ab8c47c 100644 --- a/plugins/kompose/kompose.plugin.zsh +++ b/plugins/kompose/kompose.plugin.zsh @@ -1,3 +1,18 @@ -if [ $commands[kompose] ]; then - source <(kompose completion zsh) +# Autocompletion for the Kompose CLI (kompose). +if (( ! $+commands[kompose] )); then + return +fi + +# 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/_kompose" ]]; then + kompose completion zsh | tee "$ZSH_CACHE_DIR/completions/_kompose" >/dev/null + source "$ZSH_CACHE_DIR/completions/_kompose" +else + source "$ZSH_CACHE_DIR/completions/_kompose" + zmodload -F zsh/files b:zf_mv + () { + local TMPPREFIX="$ZSH_CACHE_DIR/completions/._kompose" + zf_mv -f -- =( kompose completion zsh ) "$ZSH_CACHE_DIR/completions/_kompose" + } &| fi diff --git a/plugins/kops/kops.plugin.zsh b/plugins/kops/kops.plugin.zsh index 0c38ce2df..30b1f22df 100644 --- a/plugins/kops/kops.plugin.zsh +++ b/plugins/kops/kops.plugin.zsh @@ -1,3 +1,18 @@ -if [ $commands[kops] ]; then - source <(kops completion zsh) +# Autocompletion for the Kubernetes Operations CLI (kops). +if (( ! $+commands[kops] )); then + return +fi + +# 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/_kops" ]]; then + kops completion zsh | tee "$ZSH_CACHE_DIR/completions/_kops" >/dev/null + source "$ZSH_CACHE_DIR/completions/_kops" +else + source "$ZSH_CACHE_DIR/completions/_kops" + zmodload -F zsh/files b:zf_mv + () { + local TMPPREFIX="$ZSH_CACHE_DIR/completions/._kops" + zf_mv -f -- =( kops completion zsh ) "$ZSH_CACHE_DIR/completions/_kops" + } &| fi diff --git a/plugins/oc/oc.plugin.zsh b/plugins/oc/oc.plugin.zsh index f0e2fc3bc..c2e152ac5 100644 --- a/plugins/oc/oc.plugin.zsh +++ b/plugins/oc/oc.plugin.zsh @@ -2,7 +2,20 @@ # # Author: https://github.com/kevinkirkup -if [ $commands[oc] ]; then - source <(oc completion zsh) - compdef _oc oc +if (( ! $+commands[oc] )); then + return +fi + +# 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/_oc" ]]; then + oc completion zsh | tee "$ZSH_CACHE_DIR/completions/_oc" >/dev/null + source "$ZSH_CACHE_DIR/completions/_oc" +else + source "$ZSH_CACHE_DIR/completions/_oc" + zmodload -F zsh/files b:zf_mv + () { + local TMPPREFIX="$ZSH_CACHE_DIR/completions/._oc" + zf_mv -f -- =( oc completion zsh ) "$ZSH_CACHE_DIR/completions/_oc" + } &| fi diff --git a/plugins/operator-sdk/operator-sdk.plugin.zsh b/plugins/operator-sdk/operator-sdk.plugin.zsh index baeb01a80..2f12b1fe4 100644 --- a/plugins/operator-sdk/operator-sdk.plugin.zsh +++ b/plugins/operator-sdk/operator-sdk.plugin.zsh @@ -1,4 +1,18 @@ -if [ $commands[operator-sdk] ]; then - source <(operator-sdk completion zsh) - compdef _operator-sdk operator-sdk +# Autocompletion for the Operator SDK CLI (operator-sdk). +if (( ! $+commands[operator-sdk] )); then + return +fi + +# 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/_operator-sdk" ]]; then + operator-sdk completion zsh | tee "$ZSH_CACHE_DIR/completions/_operator-sdk" >/dev/null + source "$ZSH_CACHE_DIR/completions/_operator-sdk" +else + source "$ZSH_CACHE_DIR/completions/_operator-sdk" + zmodload -F zsh/files b:zf_mv + () { + local TMPPREFIX="$ZSH_CACHE_DIR/completions/._operator-sdk" + zf_mv -f -- =( operator-sdk completion zsh ) "$ZSH_CACHE_DIR/completions/_operator-sdk" + } &| fi diff --git a/plugins/please/please.plugin.zsh b/plugins/please/please.plugin.zsh index 0f58307ab..e4d2a7008 100644 --- a/plugins/please/please.plugin.zsh +++ b/plugins/please/please.plugin.zsh @@ -1,5 +1,20 @@ -if (( $+commands[plz] )); then - source <(plz --completion_script) +# Autocompletion for the Please build system CLI (plz). +if (( ! $+commands[plz] )); then + return +fi + +# 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/_plz" ]]; then + plz --completion_script | tee "$ZSH_CACHE_DIR/completions/_plz" >/dev/null + source "$ZSH_CACHE_DIR/completions/_plz" +else + source "$ZSH_CACHE_DIR/completions/_plz" + zmodload -F zsh/files b:zf_mv + () { + local TMPPREFIX="$ZSH_CACHE_DIR/completions/._plz" + zf_mv -f -- =( plz --completion_script ) "$ZSH_CACHE_DIR/completions/_plz" + } &| fi alias pb='plz build' diff --git a/plugins/svcat/svcat.plugin.zsh b/plugins/svcat/svcat.plugin.zsh index f90e7d8d6..396877d72 100644 --- a/plugins/svcat/svcat.plugin.zsh +++ b/plugins/svcat/svcat.plugin.zsh @@ -1,6 +1,18 @@ -# Autocompletion for svcat. -# +# Autocompletion for the Service Catalog CLI (svcat). +if (( ! $+commands[svcat] )); then + return +fi -if [ $commands[svcat] ]; then - source <(svcat completion zsh) +# 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/_svcat" ]]; then + svcat completion zsh | tee "$ZSH_CACHE_DIR/completions/_svcat" >/dev/null + source "$ZSH_CACHE_DIR/completions/_svcat" +else + source "$ZSH_CACHE_DIR/completions/_svcat" + zmodload -F zsh/files b:zf_mv + () { + local TMPPREFIX="$ZSH_CACHE_DIR/completions/._svcat" + zf_mv -f -- =( svcat completion zsh ) "$ZSH_CACHE_DIR/completions/_svcat" + } &| fi