Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get my iTerm prompt to display differently when I'm in a Git branch?

Tags:

I'm trying to get my iTerm prompt set up the same way as Paul Irish

So far I have the following in ~/.profile:

# Add git branch name to prompt parse_git_branch() {   git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/*\(.*\)/ on \1/' }  PS1='\n\[\033[0:35m\]\u\[\033[0;32m\]\w\[033[0m\]$(parse_git_branch)\n\$\[\033[0m\] ' 

I don't know how to make just the branch appear in a different colour and not the preceding "on"

As well as this there are other features such as:

  • Displaying an "o" at the prompt when not in a git branch
  • Displaying a "±" when in a branch
  • Displaying the date at the end of the line

Any help would be appreciated

like image 605
purinkle Avatar asked Mar 31 '11 19:03

purinkle


1 Answers

I use git-aware-prompt.

A lot of solutions I had before only displayed the git branch if I were only in that directory when the terminal loaded. If I started iTerm in a non-git repo, then it wouldn't work when I cd into directory with a git repo.

This github project solved that for me.

like image 138
spong Avatar answered Oct 22 '22 12:10

spong