Skip to content

Instantly share code, notes, and snippets.

@todd-cook
Created February 5, 2019 19:58
Show Gist options
  • Save todd-cook/f1d7d3ecb62e0da079aaa1418ac49cfa to your computer and use it in GitHub Desktop.
Save todd-cook/f1d7d3ecb62e0da079aaa1418ac49cfa to your computer and use it in GitHub Desktop.
Display git branch in terminal title, bash functions
# Add to .bash_profile
function gittitle() {
echo -n -e "\033]0;`git status | awk 'NR==1 {print $3}'`\007"
}
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment