Sleeping Cyborg

Jonathan David Page talks about whatever he happens to be thinking about. Sometimes other people join in.

Email · @parathetic (Twitter) · @jdpage (Github)
Subscribe to feed


A collection of cool people and projects.

Mercurial Current Branch Bash Prompt Revisited

by on 17 June 2011
with some comments, maybe.

Since I published Mercurial current branch in your Bash prompt in April, I've made some improvements.

The first is that, in a freshly initialized Mercurial repo, reporoot/.hg/branch isn't written, so fasthgbranch doesn't find anything. The fix for this is simple: just output "default" if you find a Mercurial repo, but no branch file.

The second is that it now works on Mac OS X (and probably, by extension, *BSD). I recently got a programming job (where we use Mercurial!), and my work computer is a Mac. Porting to OS X involved two changes. Firstly, I had to replace the Linux-only system call get_current_dir_name() with the equivalent getcwd(NULL, 0), which is also a Linux extension to POSIX, but happens to work on OS X too. Secondly, OS X sed behaves slightly differently from GNU sed. GNU sed supports both "&" and "\0" to mean "the entire match", while OS X sed only supports &.

All of these improvements have been reflected in the original article.