Skip to content

Instantly share code, notes, and snippets.

@eguven
Created January 23, 2020 16:38
Show Gist options
  • Save eguven/6ef5eade285e830219126e20b541ed0b to your computer and use it in GitHub Desktop.
Save eguven/6ef5eade285e830219126e20b541ed0b to your computer and use it in GitHub Desktop.
Shell functions to quickly show and switch kubernetes contexts.
function k-enabled() {
if [ ! -z "$PS1_LAST" ]; then
return 0
fi
return 1
}
# show current context
function k-on() {
if k-enabled; then
k-off
fi
export PS1_LAST=$PS1
export PS1="[$(kubectl config current-context)] $PS1"
}
# hide current context
function k-off() {
if k-enabled; then
export PS1=$PS1_LAST
unset PS1_LAST
fi
}
# switch context
function k-switch() {
kubectl config use-context $1
k-on
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment