A git quickie

by Marcus Zarra

After reading Fraser Speirs’ excellent write-up on his conversion over to git, I followed a few of the links to find a bash script to display your current git branch in the command prompt. Following yet another link from that post showed how to convert the bash script to zsh.

Here is my contribution to move that from the prompt to the right side of the screen.

function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
function precmd() { RPS1="%~$(parse_git_branch)" }
export PS1='> '

Note that the last line just gives me a very short left hand prompt which I prefer.

Uploaded with plasq‘s Skitch!

Marcus Zarra

Marcus S. Zarra is a founding partner of MartianCraft, LLC. He has been developing Cocoa software since 2003, Java software since 1996, and has been in the industry since 1985. Currently Marcus is producing software for iOS and OS X. In addition to writing software, he assists other developers by blogging about development and supplying code samples on Cocoa Is My Girlfriend. Marcus is also the author of Core Data (2nd edition): Data Storage and Management for iOS, OS X, and iCloud and Co-Author of Core Animation: Simplified Animation Techniques for Mac and iPhone Development. You can find Marcus on Twitter, on App.net and on StackOverflow.

More Posts - Website

Follow Me:


jagipson says:

Thank you for your informative article. I was a Windows programmer until .NET was rolled out. Disgusted by the prospect of having to relearn everything after all the time I had invested in learning Win32/COM/ActiveX I turned away from GUI programming and banished myself to the land of various scripting and shell languages. For the last couple of years I’ve been trying to get a handle on Cocoa but I keep stumbling on the MVC architecture (And since I have Rails experience one wouldn’t expect it).

My questions are more philosophical in nature. The tone of most MVC programmers is from the core assumption that everyone understands and agrees with the virtues of MVC. From my ragged attempts at Cocoa, I found most of my code goes in Controllers. If the purpose of MVC is to provide the ability to recycle View code and Model code, but 90% of my code goes in the Controller which has to be thrown away (or modified) if either the Model or View change, then why use MVC? I’m obviously missing something about MVC. What is it?

And please don’t flame me for putting my cards on the table. What good is the public forum if everyone that appeals to it risks a flogging. If people lazily dismiss me as dense, then I shall have to retreat back to my Unix Ivory tower and will never learn to love Cocoa. Thanks.

Matt Long says:

This is a good comment, but it looks like you posted it in the wrong place. Feel free to repost it in the Windows OOP vs Cocoa MVC comments section.