Skip to content

Instantly share code, notes, and snippets.

@djromero
Last active December 14, 2015 08:09
Show Gist options
  • Save djromero/5055363 to your computer and use it in GitHub Desktop.
Save djromero/5055363 to your computer and use it in GitHub Desktop.
git branch on bash prompt and terminal tab/window title bar
get_dir() {
printf "%s" $(pwd | sed "s:$HOME:~:")
}
rename_tab() {
echo -ne "\033]0;"$@"\007"
}
rename_tab_git_branch() {
branch=`git symbolic-ref HEAD 2>/dev/null | cut -d/ -f3`
if [ "$branch" != "" ]; then
rename_tab $branch
else
rename_tab $(get_dir)
fi
}
GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_SHOWCOLORHINTS="yes"
source ~/.git-prompt.sh
source ~/.git-completion.sh
export PROMPT_COMMAND='__git_ps1 "\u@\h:\W" "\\\$ ";rename_tab_git_branch;'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment