Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bfleming-ciena/337fb43582cc02694ab1ff7e5db42689 to your computer and use it in GitHub Desktop.
Save bfleming-ciena/337fb43582cc02694ab1ff7e5db42689 to your computer and use it in GitHub Desktop.
kubernetes cluster and namespace bash prompt (tested with os-x)
# Sorry for not mentioning the credit to the original author. I lost the original link. I just added the namespace to the picture.
function kube_context() {
# could have used $?, but it was easier with a string compare
local ctx=$(kubectl config current-context 2>&1)
local ns=$(kubectl config get-contexts --no-headers | grep '*' | awk '{print $5}')
if [ "${ctx}" != "error: current-context is not set" ]; then
echo -n "<${ctx}:$ns> "
fi
}
Blue='\e[0;34m' # Blue
White='\e[0;37m' # White
BRed='\e[1;31m' # Red
IWhite='\e[0;97m' # White
LightBlue='\e[1;34m'
PS1="\[$Blue\]\t\[$BWhite\]\[$LightBlue\] \$(kube_context)\[$BRed\]\[$BRed\]\w\[\033[m\]\[$IWhite\]\$(__git_ps1)\[$White\]\$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment