ANN: __hg_ps1

Kevin Bullock kbullock+mercurial at ringworld.org
Wed Apr 15 23:26:52 CDT 2009


Hello all—

As mentioned on IRC a couple days ago, I've implemented a shell prompt  
helper for Mercurial repositories, similar to __git_ps1. It is  
intended to be called from your custom prompt string (PS1 in bash and  
related shells). If your working directory is in a repository, it  
prints the current branch name, and appends either a '!' if there are  
modified files in the working directory, a '?' if there are untracked  
files, or nothing if the repository is clean.

For example:

~/repo$ hg st
A .hgignore
~/repo$ PS1='$(__hg_ps1)\n'$PS1
on default!                       # PS1 calls __hg_ps1
~/repo$

__hg_ps1 is a pure Python implementation, thus it only fires up the  
Python interpreter once per invocation. Previous shell-based solutions  
ran 'hg' 3-4 times per prompt.

It's available on bitbucket: <http://bitbucket.org/krbullock/hg_ps1/>.  
Fork, hack, submit pull requests. I've even already gotten a few. Also  
feel free to submit issues there.

Pacem in terris / Mir / Shanti / Salaam / Heiwa
Kevin R. Bullock

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://selenic.com/pipermail/mercurial/attachments/20090415/36653270/attachment.htm 


More information about the Mercurial mailing list