Created
January 23, 2020 16:38
-
-
Save eguven/6ef5eade285e830219126e20b541ed0b to your computer and use it in GitHub Desktop.
Shell functions to quickly show and switch kubernetes contexts.
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
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