I am using the git-prompt.sh script to show the git status at the bash command prompt. Using the PROMPT_COMMAND method to also have colors:

.bashrc :

source ~/.bash.d/git-prompt.sh # Show git branch name at command prompt

# use existing PS1 settings
PROMPT_COMMAND=$(sed -r 's|^(.+)(\\\$\s*)$|__git_ps1 "\1" "\2"|' <<< $PS1)

This works so far in regard of showing the git status, but it does not show the conda environment anymore.

When I comment out the line with PROMPT_COMMAND=..., the conda env is displayed, e.g.

(base) [user@linux ~]$

Apparently the problem is that git-prompt.sh uses PROMPT_COMMAND and conda uses PS1.

Is there a way to achieve this? Maybe showing the conda env with PROMPT_COMMAND?


You can just configure your PS1 to show the git branch by adding a function right above your PS1 declaration:

git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'

Then, you simply place \$(git_branch) wherever you'd like in your PS1, and colorize it as usual.

If you need more details, this blog shows you how.

| improve this answer | |
  • It works and does the show the git branch. I think it should be $(git_branch) though (without the \). But it doesn't provide all the features you get with git-prompt.sh and PROMPT_COMMAND – jost21 Aug 13 '19 at 7:31

You can just add the following line at the end of your bashrc.


as an example mine looks like this

export PROMPT_COMMAND='__git_ps1 "${CONDA_PROMPT_MODIFIER}${ORIG_PS1}" "\n\\[\033[00m\]> "'
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.