Friday, March 5, 2010

Git Bash Prompt

To get a bash prompt like this:
~/Sites/project [master] $


Add this to your /etc/profile file. Once done, save it and open a new prompt.

function parse_git_branch {
 ref=$(git symbolic-ref HEAD 2> /dev/null) || return
 echo "["${ref#refs/heads/}"] "
}

WHITE="\[\033[1;37m\]"
LIGHTGRAY="\[\033[0;37m\]"
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
LIGHTCYAN="\[\033[0;36m\]"
GREEN="\[\033[0;32m\]"

PS1="$LIGHTGRAY\w $LIGHTCYAN\$(parse_git_branch)$GREEN$ "

Bash colors tutorial:
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html

Another git prompt tutorial:
http://railstips.org/blog/archives/2009/02/02/bedazzle-your-bash-prompt-with-git-info/

No comments:

Post a Comment