-- markdown --
__hg_ps1 is 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.
~/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. Shell-based solutions like the one
Steve Losh published start multiple Python interpreters every time the
prompt is printed; this implementation only needs to run one interpreter.
To install, run the setup script:
python setup.py install
This will install the source as an egg in your Python site-packages directory,
__hg_ps1 into (most likely)
install --help for more options.)
Be sure to run
setup.py with the same version of Python that Mercurial uses.
On Mac OS X Leopard, to use
__hg_ps1 with the version of Mercurial from
/usr/bin/python, as follows:
$ /usr/bin/python setup.py [command]
This shouldn't be a concern unless you have multiple Python interpreters installed (e.g. through Fink or MacPorts).
Thanks to Jannis Leidel firstname.lastname@example.org for creating the setup script and reworking the code into module form.
Setting your prompt
You can then add it into your prompt string. In bash, for example, you might set the following in ~/.bashrc:
# ~/.bashrc PS1='$(__hg_ps1)\n'$PS1
If you already have a custom prompt string, add the above line after it--don't replace it. For example:
# ~/.bashrc PS1='\u@\h \w\$ ' PS1='$(__hg_ps1)\n'$PS1