git + bash + awk = crazy delicious*
May 5th, 2008 by vinbarnes 4 comments »
This is mainly for the benefit of Wilkes. I'm sure there are better ways, but here's what I have in my bash profile for knowing when your git branch is dirty.
function git_current_branch {
git branch 2>/dev/null | awk '/^\* /{print " on " $2}'
}
function git_dirty {
git st 2>/dev/null | wc -l | awk '{if ($1 > 2) print "*"}'
}
export PS1="[\u@\h:\W\$(git_current_branch)\$(git_dirty)]$ "
I've noticed a problem in one or two cases where it advertises The Dirty but nothing really is. But those cases are so rare that I ignore them. I think I remember some people talking about coloring the output as well. I like it simple so I'll stick with this, but if there are better ways then show me the way -- I may take the leap.
May 5th, 2008 at 02:13 AM
Yep, I use color:
http://www.madstop.com/tools/git_branch_in_your_bash_prompt.html
May 5th, 2008 at 07:35 AM
I also found some problems with Unknown Dirtiness with the line-counting method, not that I can remember them now. In the end, I went with counting colons, which is what Luke shows as well. In fact, I think we went back and forth on that at a NashDL meeting and hammered out the problems.
May 17th, 2009 at 04:07 PM
Blog added to my favorites! :-)
May 17th, 2009 at 04:10 PM
Blog added to my favorites! :-)