1

Before anyone says it, yes, I know this is a duplicate, except when I copy/paste that code into tilde slash period bash(no period)rc, the terminal hasn't changed at all.

I'm running Debian on Virtual Box (Windows 10). I'm guessing I'm using the Mate desktop because I'm using Mate terminal.

When I go into a directory with git, I need to type in git status or git branch to see what branch I'm on, it doesn't display it like it's supposed to with the code.

EDIT: The code I pasted

force_color_prompt=yes
parse_git_branch() {
 git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
 PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi
unset color_prompt force_color_prompt

EDIT 2:So it turns out my .bashrc file had

 if [ "$color_prompt" = yes ]; then
     PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
    else
     PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
    fi
    unset color_prompt force_color_prompt

printed somewhere else in it. I commented that out and now I get branch (whatever) when I'm in a git directory without needing to type git branch or git status. The problem I have now is the colors won't show up. This isn't a major issue, though it would be nice to have.

  • Did you try and run the command in parse_git_branch function manually in a terminal at a git repository location? – AmeyaVS Dec 20 '18 at 4:35
  • @AmeyaVS, when I run git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' in a git directory, I get the branch I'm on in parentheses – 00Saad Dec 20 '18 at 4:37
  • Can you update the question post with the output? – AmeyaVS Dec 20 '18 at 4:40
0

You may need to source the file again. Either log out or do this:

source ~/.bashrc
0

It is probably you are missing the PS1 prompt configuration for your user id.
You probably can use this which has those features and more.

Update
Here is my PS1 bash shell prompt with added escape sequences for the colors:

export PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\[\033[1;36m\]\$(parse_git_branch)\[\033[00m\]\n\$ "

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.