bash-git-prompt icon indicating copy to clipboard operation
bash-git-prompt copied to clipboard

kube-ps1

Open dhoffi opened this issue 5 years ago • 3 comments

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?

dhoffi avatar Apr 15 '20 16:04 dhoffi

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

askoriy avatar May 05 '20 12:05 askoriy

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

agilgur5 avatar Jun 11 '20 04:06 agilgur5