Skip to content

Instantly share code, notes, and snippets.

@vitebo
Forked from viniciusjssouza/kubectl_context.sh
Last active January 3, 2020 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitebo/7e5e02b78c0416720c74935fedd4f930 to your computer and use it in GitHub Desktop.
Save vitebo/7e5e02b78c0416720c74935fedd4f930 to your computer and use it in GitHub Desktop.
show kubectl context on bash
# .bash_profile
NORMAL="\[\033[00m\]"
BLUE="\[\033[01;34m\]"
YELLOW="\[\e[1;33m\]"
GREEN="\[\e[1;32m\]"
source $HOME/kube-prompt.sh
export PS1="${BLUE}\W ${GREEN}\u${YELLOW}\$(__kube_ps1)${NORMAL} \$ "
# 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment