bash-git-prompt
bash-git-prompt copied to clipboard
kube-ps1
Hi,
I would like to run git-prompt together with kube-ps1 https://github.com/jonmosco/kube-ps1
but any try f...s up the whole prompt.
Any ideas on who to best achieve this?
Instead rewrite PS1 variable I achieved this by add kube_ps1 to PROMPT_COMMAND variable (with new line for better visibility):
if [[ -n "$PROMPT_COMMAND" ]]; then
PROMPT_COMMAND="kube_ps1; echo; $PROMPT_COMMAND"
else
PROMPT_COMMAND="kube_ps1"
fi
You need to configure prompt_callback for this because kube-ps1 is dynamic (configuring plain GIT_PROMPT_END won't work as it will get stale):
# customize Git prompt below with kube_ps1
function prompt_callback() {
echo -n " $(kube_ps1)"
}
Full excerpt from my bash_profile:
# add kube_ps1 function for a Bash prompt / PS1 for k8s
if [ -f "$(brew --prefix)/opt/kube-ps1/share/kube-ps1.sh" ]; then
source "$(brew --prefix)/opt/kube-ps1/share/kube-ps1.sh"
fi
# customize Git prompt below with kube_ps1
function prompt_callback() {
echo -n " $(kube_ps1)"
}
# Bash prompt / PS1 for Git -- prompt is dynamic and uses prompt_callback above
if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then
__GIT_PROMPT_DIR=$(brew --prefix)/opt/bash-git-prompt/share
source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh"
fi