guest@dotshare [~/groups/shells/bash] $ ls git-branch-in-PS1/ | cat

git branch in PS1 (raw, dl) (+2 likes)

mburns Jun 25, 2011 (shells/bash)
1
2
3
4
5
function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

PS1="\[\033[01;32m\]\u@\h {\[\033[01;34m\]\w\$(parse_git_branch)\[\033[01;32m\]} \[\033[01;34m\]\$\[\033[00m\] "

CLICK TO VIEW

x

Notes

This script detects if you are in a git repo and adds the current branch to your PS1

{~} $
{~} $ cd repo
{~/repo(master)} $