Kubernetes context selector (with ZSH completions)
# 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