Git Status in Command Line
There are many tricks out there to get the git status to show in the command line path, but here’s one that worked the best for me on a Mac OS X Snow Leopard machine.
Download the git source, and open the directory in terminal. There’s a completion script you need to move to your system:
$ cp contrib/completion/git-completion.bash /opt/git/git-completion
The location of where you place this file is up to you. Next you need to edit your bash profile to load the script and add in the code necessary to append the branch name output:
$ vi ~/.bash_profile
Trigger editing mode by pressing “i” and paste in the following code below any existing content:
. /opt/git/git-completion
PS1='\h:\W$(__git_ps1 "(%s)") \u\$ '
RED="\[\033[0;31m\]"
GREEN="\[\033[0;32m\]"
YELLOW="\[\033[0;33m\]"
BLUE="\[\033[0;34m\]"
PURPLE="\[\033[0;35m\]"
TEAL="\[\033[0;36m\]"
GRAY="\[\033[0;37m\]"
WHITE="\[\033[0;38m\]"
PS1="$TEAL\h: $GRAY\W$GREEN \$(__git_ps1 '(%s)')$WHITE \$ "
Hit escape and type “:wq” to save and quit.
A nice extra step is to ask git to color it’s status output:
$ git config color.ui true
Exit terminal entirely and open it in a git-controlled directory and you should see your status and coloring.
You’ll be able to find a large collection of additional customizations at: http://asemanfar.com/Current-Git-Branch-in-Bash-Prompt
No related posts.