Skip to content

Instantly share code, notes, and snippets.

@lstanard
Created August 7, 2016 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lstanard/1c17b4cfc205208a552fd1364cb47939 to your computer and use it in GitHub Desktop.
Save lstanard/1c17b4cfc205208a552fd1364cb47939 to your computer and use it in GitHub Desktop.
Add git branch name to bash prompt
function parse_git_branch {
ref=$(git status 2> /dev/null | grep -E "(On branch|detached) .*$" | grep -oE "\S*$") || return
echo "["${ref#refs/heads/}"] "
}
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
PS1='\[\033[0;33m\]$(parse_git_branch)\[\e[32m\]\W\[\e[33m\]: \[\e[0m\]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment