Created
August 14, 2018 15:50
-
-
Save sudhirpandey/a295415c2dfd6c36faf1c606d4ec896e to your computer and use it in GitHub Desktop.
context aware for kubectl and oc client
This file contains hidden or 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
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