JMK
JMK

Reputation: 28059

Can I setup terminal in Ubuntu to tell me what branch I am in?

Wasn't sure whether this was for here or Superuser, opted for here but will move if neccessary.

Can I setup terminal on Ubuntu to display the branch name when in a Git repository? On Git Bash for Windows, this happens automatically, and the same functionality would be really handy on Ubuntu, does it exist? Is there some command I can enter to turn this functionality on?

Thanks

Upvotes: 0

Views: 291

Answers (1)

MathieuB
MathieuB

Reputation: 88

I've done this by adding the following to my ~/.bashrc file:

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

function proml {
   local BLUE="\[\033[0;34m\]"
   local DEFAULT="\[\033[0m\]" 
   PS1="\u@\h$BLUE\$(parse_git_branch)$DEFAULT-> \w\n\$ "
}
proml

This gives me the following invite:

[myusername@mymachinename [branch_name] current_folder]$

I'm not expert in linux though, there may be better ways to do this...

Upvotes: 1

Related Questions