Last active
July 8, 2020 07:15
-
-
Save dplusic/eb06fd8921c6a6002892fb1d8dfb1dd2 to your computer and use it in GitHub Desktop.
Change $KUBECONFIG
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
#!/usr/bin/env bash | |
# Usage: source ./kube-use-context.sh <CONTEXT_NAME> | |
BASEDIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: ${BASH_SOURCE[0]} <CONTEXT_NAME>" | |
return | |
fi | |
CONTEXT_NAME=$1 | |
KUBECONFIG=$BASEDIR/config-$CONTEXT_NAME | |
if [ ! -f "$KUBECONFIG" ]; then | |
echo "$CONTEXT_NAME does not exists." | |
return | |
fi | |
if [ -n "$_KUBE_CONTEXT_NAME" ] && [[ $PS1 == "($_KUBE_CONTEXT_NAME) "* ]]; then | |
PS1=${PS1/\($_KUBE_CONTEXT_NAME\) /} | |
fi | |
export PS1="($CONTEXT_NAME) $PS1" | |
export KUBECONFIG | |
export _KUBE_CONTEXT_NAME=$CONTEXT_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment