public
Created

Display current Git branch and root directory in Mac OS X Terminal title bar.

  • Download Gist
.bash_profile
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# Add to .bash_profile
 
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
 
get_git_root() {
basename $(git rev-parse --show-toplevel 2> /dev/null) 2> /dev/null
}
 
update_git_prompt()
{
GIT_BRANCH=$(parse_git_branch)
 
if [ -n "$GIT_BRANCH" ]; then
GIT_ROOT=$(get_git_root)
echo -ne "\033]0;$(get_git_root): $(parse_git_branch)\007"
else
echo -ne "\033]0;\007"
fi
}
 
PROMPT_COMMAND="update_git_prompt; $PROMPT_COMMAND"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.