5b717ab3e4bfb627a936d7c04367a39867734d63

Author
IsThisTheMatrix <46820823+causalityloop@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

kubectl: verify kubectl is installed before running compdef (#9346)

Diff

 1diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh
 2index 6292a0b2f2982629c0b2c9e7c8999793aba811f2..7a0c47945a5a0594a735babcabce31edefacf0b8 100644
 3--- a/plugins/kubectl/kubectl.plugin.zsh
 4+++ b/plugins/kubectl/kubectl.plugin.zsh
 5@@ -150,19 +150,13 @@ alias kepvc='kubectl edit pvc'
 6 alias kdpvc='kubectl describe pvc'
 7 alias kdelpvc='kubectl delete pvc'
 8 
 9-# Colored JSON output
10-kj() {
11-  kubectl "$@" -o json | jq
12-}
13-compdef kj=kubectl
14-
15-kjx() {
16-  kubectl "$@" -o json | fx
17-}
18-compdef kjx=kubectl
19+# Only run if the user actually has kubectl installed
20+if (( $+commands[kubectl] )); then
21+  kj() { kubectl "$@" -o json | jq; }
22+  kjx() { kubectl "$@" -o json | fx; }
23+  ky() { kubectl "$@" -o yaml | yh; }
24 
25-# Colored YAML output
26-ky() {
27-  kubectl "$@" -o yaml | yh
28-}
29-compdef ky=kubectl
30+  compdef kj=kubectl
31+  compdef kjx=kubectl
32+  compdef ky=kubectl
33+fi