Skip to content

Instantly share code, notes, and snippets.

@ericsaboia
Last active December 25, 2015 19:29
Show Gist options
  • Save ericsaboia/7027863 to your computer and use it in GitHub Desktop.
Save ericsaboia/7027863 to your computer and use it in GitHub Desktop.
Display Git Branch or Tag Names in your Bash Prompt
# Replace your PS1, inside ~/.bashrc for this:
# source ~/.bashrc_git
# PS1='\w\[\033[0;32m\]$(parse_git_branch_or_tag)\[\033[00m\]: '
parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
parse_git_tag () {
git describe --tags 2> /dev/null
}
parse_git_branch_or_tag() {
local OUT="$(parse_git_branch)"
if [ "$OUT" == " ((no branch))" ]; then
OUT=" ($(parse_git_tag))";
fi
echo "$OUT"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment