Announcing __hg_ps1

You may know that Git’s bash completion defines a function, __git_ps1, designed to be called from your shell prompt string. If you happen to be in a git repository, it spits out what branch you’re on.

Similar things for Mercurial have been written up, but they call hg repeatedly from bash functions. That means for each time your prompt is printed, the Python interpreter gets fired up three or four times. My implementation is written in Python using Mercurial’s API, so it only starts one external process.

Find it on bitbucket: http://bitbucket.org/krbullock/hg_ps1. Feel free to submit issues there, or write patches and submit pull requests.

Update 4 Oct 2009: Steve Losh went and one-upped me with a Mercurial extension, hg-prompt. It’s much more flexible than what I did with __hg_ps1, and last night I took the time to add MQ support to it. I’d recommend switching to it if you’re using __hg_ps1.


About this entry