Last active
December 25, 2015 19:29
-
-
Save ericsaboia/7027863 to your computer and use it in GitHub Desktop.
Display Git Branch or Tag Names in your Bash Prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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