Created
January 17, 2017 21:04
-
-
Save kirsle/9f7eefa8e58517956688a66c711456a6 to your computer and use it in GitHub Desktop.
Show current git branch name in Bash prompt
This file contains 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
# Function that prints the branch name. | |
git_branch() { | |
branch=`git branch 2> /dev/null | sed -e '/^[^*]/d' | perl -pe 's/^\*\s+//g'` | |
if [ "$branch" != '' ]; then | |
echo -n " ($branch)" | |
fi | |
} | |
# Integrate it into your $PS1 prompt. | |
# Would look like: [user@localhost myapp (master)]$ | |
export PS1="[\u@\h \W\$(git_branch)]\$ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment