Skip to content

Instantly share code, notes, and snippets.

@viniciusjssouza
Last active January 2, 2020 22:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save viniciusjssouza/df2669da5b47a54ccf4895f61db289ee to your computer and use it in GitHub Desktop.
Save viniciusjssouza/df2669da5b47a54ccf4895f61db289ee to your computer and use it in GitHub Desktop.
show kubectl context on bash
# kube-prompt.sh
#!/bin/bash
__kube_ps1()
{
# Get current context
CONTEXT=$(cat ~/.kube/config | grep "current-context:" | sed "s/current-context: //")
if [ -n "$CONTEXT" ]; then
echo "(k8s: ${CONTEXT})"
fi
}
# .bash_profile
NORMAL="\[\033[00m\]"
BLUE="\[\033[01;34m\]"
YELLOW="\[\e[1;33m\]"
GREEN="\[\e[1;32m\]"
source ~/kube-prompt.sh
export PS1="${BLUE}\W ${GREEN}\u${YELLOW}\$(__kube_ps1)${NORMAL} \$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment