Skip to content

Instantly share code, notes, and snippets.

@rcoup
Created August 13, 2018 08:14
Show Gist options
  • Save rcoup/e52968336b7ccade1bf031ffab36d847 to your computer and use it in GitHub Desktop.
Save rcoup/e52968336b7ccade1bf031ffab36d847 to your computer and use it in GitHub Desktop.
bashrc for kubernetes context & namespace
__kube_ps1()
{
# Get current context
CONTEXT="$(kubectl config current-context)"
if [ -n "$CONTEXT" ]; then
NAMESPACE="$(kubectl config view -o=jsonpath="{.contexts[?(@.name==\"${CONTEXT}\")].context.namespace}")"
echo "⎈ $CONTEXT:${NAMESPACE:-default}"
fi
}
PS1='... \[\e[38;5;27m\]$(__kube_ps1) ...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment