sergserg sergserg - 1 year ago 141
Git Question

How can I display the current branch and folder path in terminal?

I've been watching some of the Team Treehouse videos and they have a very nice looking terminal when working with Git.

For example they have (something similar):

mike@treehouseMac: [/Work/test - feature-branch-name] $ git add .
mike@treehouseMac: [/Work/test - feature-branch-name] $ git commit -m "Some feature."
mike@treehouseMac: [/Work/test - feature-branch-name] $ git checkout master
mike@treehouseMac: [/Work/test - master] $ git status

How can my terminal show me some useful information of what branch I'm on, with colors to distinguish bits of the data I want? Is there some sort of de-facto plugin I haven't found yet?

I'm using Mac OSX 10.8

Answer Source

It's not about a plugin. It's about prompt tricks in the shell.

For a cool setup in bash, check out the dotfiles project of this guy:

To get a fancy prompt, include the .bash_prompt in your ~/.bash_profile or ~/.bashrc.

To get the exact same prompt as in your question, change the export PS1 line at the end of .bash_prompt like this:

export PS1="\[${BOLD}${MAGENTA}\]\u\[$WHITE\]@\[$ORANGE\]\h\[$WHITE\]: [\[$GREEN\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" - \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]] \$ \[$RESET\]"

I ended up using all the .bash* files from this repository about a month ago, and it's been really useful for me.

For Git, there are extra goodies in .gitconfig.

And since you're a mac user, there are even more goodies in .osx.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download