-
-
Save JoseRobertoR/5c9e02b535a5483e69e96504f8093da0 to your computer and use it in GitHub Desktop.
Kubernetes PS1
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="\[\033[00m\]" | |
BLUE="\[\033[01;34m\]" | |
RED="\[\e[1;31m\]" | |
YELLOW="\[\e[1;33m\]" | |
GREEN="\[\e[1;32m\]" | |
PS1_WORKDIR="\w" | |
PS1_HOSTNAME="\h" | |
PS1_USER="\u" | |
__kube_ps1() | |
{ | |
CONTEXT=$(kubectl config current-context) | |
if [ -n "$CONTEXT" ]; then | |
case "$CONTEXT" in | |
*prod*) | |
echo "${RED}(k8s: ${CONTEXT})" | |
;; | |
*test*) | |
echo "${YELLOW}(k8s: ${CONTEXT})" | |
;; | |
*) | |
echo "${GREEN}(k8s: ${CONTEXT})" | |
;; | |
esac | |
fi | |
} | |
export PROMPT_COMMAND='PS1="${GREEN}${PS1_USER}@${PS1_HOSTNAME}${NORMAL}:$(__kube_ps1)${BLUE}${PS1_WORKDIR}${NORMAL}\$ "' | |
# See https://twitter.com/micahhausler/status/785204875613261824 for example output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment