Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Hg-Prompt extension for Mercurial

📅 2014-May-22 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

You can add some Mercurial information to your shell prompt, but it can be quite a pain to do this using the commands in Mercurial. Steve Losh created the Hg-Prompt extension purely for the purpose of using it in shell prompts.

To install this extension, first clone the repository somewhere:

$ hg clone https://bitbucket.org/sjl/hg-prompt/

And add the path to the prompt.py in your hgrc file:

[extensions]
prompt = /path/to/hg-prompt/prompt.py

The extension comes with keywords which are listed here. For example, to get the count of incoming changes:

$ hg prompt "{No of incoming changes: {incoming|count}}"

The great thing about this is that if there is no incoming changes, none of the text is printed.

You can easily adapt Hg-Prompt into your shell. For example, in the fish shell, you can print out the incoming changes like this in its fish_prompt.fish:

echo (hg prompt "{No of in changes: {incoming|count}}")

Note: I found Hg-Prompt to be too slow for use as part of command prompt. I switched to VCPrompt.

Tried with: Mercurial 2.8.2 and Ubuntu 14.04