957eb77239d5c7551528cd6059418ab4e0179ba5

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

Merge pull request #6844 from lbolla/Issue6843

Cache kubectl completion script to file to speed up sourcing

Diff

 1diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh
 2index ec1321d8be2ad22b325e67e8cf72af730156c4bd..c4e30dacda6b30226b7b12d5e5f26c6da503bf17 100644
 3--- a/plugins/kubectl/kubectl.plugin.zsh
 4+++ b/plugins/kubectl/kubectl.plugin.zsh
 5@@ -1,9 +1,13 @@
 6-# Autocompletion for kubectl, the command line interface for Kubernetes
 7-#
 8-# Author: https://github.com/pstadler
 9+if (( $+commands[kubectl] )); then
10+    __KUBECTL_COMPLETION_FILE="${ZSH_CACHE_DIR}/kubectl_completion"
11 
12-if [ $commands[kubectl] ]; then
13-  source <(kubectl completion zsh)
14+    if [[ ! -f $__KUBECTL_COMPLETION_FILE ]]; then
15+        kubectl completion zsh >! $__KUBECTL_COMPLETION_FILE
16+    fi
17+
18+    [[ -f $__KUBECTL_COMPLETION_FILE ]] && source $__KUBECTL_COMPLETION_FILE
19+
20+    unset __KUBECTL_COMPLETION_FILE
21 fi
22 
23 # This command is used ALOT both below and in daily life