Created
January 11, 2021 11:26
-
-
Save plaffitt/64db828aa03df977841380340ac57400 to your computer and use it in GitHub Desktop.
My personal bash prompt, including current time and kubernetes context/namespace
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
kube_prompt() { | |
echo -n '\[\e[91m\]'$(kubectl config current-context)'\[\e[39m\]' | |
K8S_NS=$(kubectl config view --minify --output 'jsonpath={..namespace}') | |
if [[ ! -z $K8S_NS ]]; then | |
echo "|\[\e[0;32m\]$K8S_NS\[\e[39m\]" | |
fi | |
} | |
date_prompt() { | |
echo -e "$(date +%H:%M:%S).$(date +%N | cut -b1-2)" | |
} | |
PROMPT_COMMAND=__prompt_command | |
__prompt_command() { | |
local EXIT="$?" | |
PS1='${debian_chroot:+($debian_chroot)}:\[\033[01;34m\]\w\[\033[00m\]\$ ' | |
if [ $EXIT != 0 ]; then | |
PS1="[\[\e[0;31m\]${EXIT}\[\e[0m\]]${PS1}" | |
else | |
PS1="[\[\e[0;32m\]${EXIT}\[\e[0m\]]${PS1}" | |
fi | |
if env | grep -q 'ENABLE_KUBE_PROMPT'; then | |
PS1="[$(kube_prompt)]$PS1" | |
fi | |
PS1="[\[\e[90m\]$(date_prompt)\[\e[39m\]]$PS1" | |
} | |
export ENABLE_KUBE_PROMPT=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment