Skip to content

Instantly share code, notes, and snippets.

@n0nick
Created January 25, 2017 10:57
Show Gist options
  • Save n0nick/24996be8d0a7e34009ff25b1357083e7 to your computer and use it in GitHub Desktop.
Save n0nick/24996be8d0a7e34009ff25b1357083e7 to your computer and use it in GitHub Desktop.
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
@jonmosco
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment