Thursday, September 18, 2008

Hack of the day: displaying the repository location in your bash prompt

I usually want to keep track of which repository/branch the current directory is pointing at, so I wrote the following bash script to display it in the prompt. The script can handle Git and Subversion.

function is_git_repo()
{
if [ $PWD = / ]; then
return 1;
elif [ -d $PWD/.git ]; then
return 0;
else
(cd ..; is_git_repo)
fi
}

function display_vc_location()
{
if [ -d $PWD/.svn ]; then
SVNLOC=$(svn info $PWD | sed -ne 's@URL: \(.*\)@\1@p' | cut -d/ -f4-)
SVNREV=$(svn info $PWD | sed -ne 's@Revision: \(.*\)@\1@p')
echo svn\($SVNLOC@$SVNREV\)
elif is_git_repo; then
GITLOC=$(git branch -a | grep -e '^*' | cut -d' ' -f2-)
echo git\($GITLOC\)
fi
}

Add it to your PS1 variable, like this:

PS1="... \$(display_vc_location) ..."

Exercise: extract both URL and revision without running svn info twice.

Tuesday, September 16, 2008

Haiku

Inspired by an article in Dagens Nyheter:

the moose is loose
it could not find its way out
it had to be shot

Stack overflow

Short post today. 

For those of you who haven't found it yet, head over to Stack Overflow and start contributing to the collective programming knowledge heap. It's a pretty neat site for asking and answering questions about programming.

Friday, September 5, 2008

Pirate Bay and the Arboga child murders

The two murdered children in Arboga has gotten quite a media coverage here in Sweden (article from The Local, in english). Now the entire police investigation can be downloaded from Pirate Bay. I usually don't object to what the Pirate Bay does -- usually the only damages they cause are economic ones to large media companies.

But this time they are actually taking it one step further and showing immense disrespect towards two brutally murdered children who now have photos of their autopsies publically available on the internet. And since the internet never forgets, the damage is already done. Of course, the Pirate Bay people -- arrogant as they are -- don't really care: "I don't think it is our job to judge if something is ethical or unethical" (Peter Sunde). I suppose it is just a matter of time before outright criminal material such as child porn is regularly hosted by the Pirate Bay.

I'll just have to get my hands on the next season of 24 through some other channel.

I can play GTA San Andreas again! Yipiee!

A couple of months ago, GTA:SA refused to start after a driver update (no symptoms really, the game just would not start). I didn't have time to pursue the problem at the time -- I have completed all the missions and don't really play the game too much now, but it is still fun to pick up now and then.

Now after a couple of minutes googling, I found some posts indicating that a corrupt user-settings file called gta_sa.set may cause these exact symptoms. I deleted the file (it's in the My Documents\GTA San Andreas User Files directory), and now the game starts.

I'm off to running over old ladies again!!!