Created
January 25, 2017 10:57
-
-
Save n0nick/24996be8d0a7e34009ff25b1357083e7 to your computer and use it in GitHub Desktop.
Kubernetes context selector (with ZSH completions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# kubectl context switcher + completion | |
function kube-context() { | |
kubectl config use-context $@ | |
} | |
_kube-context_completions() { | |
local -a options | |
options=() | |
for c in $(kubectl config view -o jsonpath='{.contexts[*].name}'); do | |
d=$(echo $c | awk 'BEGIN { FS="_" }; { printf "%11s: %-15s %-14s", $4, $3, $2 }') | |
options=($options "$c:$d") | |
done | |
_describe 'Kubernetes contexts' options | |
} | |
compdef _kube-context_completions kube-context |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out https://github.com/jonmosco/kube-ps1