Skip to content

Instantly share code, notes, and snippets.

@sudhirpandey
Created August 14, 2018 15:50
Show Gist options
  • Save sudhirpandey/a295415c2dfd6c36faf1c606d4ec896e to your computer and use it in GitHub Desktop.
Save sudhirpandey/a295415c2dfd6c36faf1c606d4ec896e to your computer and use it in GitHub Desktop.
context aware for kubectl and oc client
NORMAL="\[\e[00m\]" # Normal
BLACK="\[\e[0;30m\]" # Black
RED="\[\e[1;31m\]" # Red
GREEN="\e[0;32m" # Green
YELLOW="\[\e[0;33m\]" # Yellow
BLUE="\[\e[0;34m\]" # Blue
PURPLE="\[\e[0;35m\]" # Purple
CYAN="\[\e[0;36m\]" # Cyan
WHITE="\[\e[0;37m\]" # White
BLACKRED="\e[41;1;30m"
__kube_ps1()
{
# Get current context
CONTEXT=$(cat ~/.kube/config | grep "current-context:" | sed "s/current-context: //" | cut -d '/' -f 1,2)
PROJ=$(echo $CONTEXT|cut -d '/' -f 1)
CLUSTER=$(echo $CONTEXT|cut -d '/' -f 2| sed "s/:.*//")
if [ -n "$CONTEXT" ]; then
if [[ $CLUSTER =~ .*-prod-.* ]];then
echo -e "${BLACKRED}(${CLUSTER}/${PROJ})"
else
echo -e "${GREEN}(${CLUSTER}/${PROJ})"
fi
fi
}
export PS1="${YELLOW}\u${NORMAL}@${RED}\H:${WHITE}\w \$(__kube_ps1)${NORMAL} \$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment