Skip to content

Instantly share code, notes, and snippets.

@jimothyGator
Created March 8, 2013 14:37
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save jimothyGator/5116840 to your computer and use it in GitHub Desktop.
Save jimothyGator/5116840 to your computer and use it in GitHub Desktop.
Display current Git branch and root directory in Mac OS X Terminal title bar.
# 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"
@avoidik
Copy link

avoidik commented Apr 5, 2017

Works also on Linux. Must have for multi-project environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment