Displaying the current git branch in your MacOS terminal shell prompt

From : https://gist.github.com/ankurk91/2efe14650d54d7d09528cea3ed432f6d

#Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^]/d' -e 's/ (.*)/ (\1)/'
export PS1="\u@\h \W[\033[32m]\$(parse_git_branch)[\033[00m] $ "

Want to find out more about these escaped codes and ANSI escape sequence color codes, here’s a good reference.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.