HTTPS SSH

HGSwift is a small shell script that generates Mercurial repository information for display in a shell prompt. It displays the default pull path, how many incoming/outgoing changesets are there and whether the working directory is modified.

This repository includes a screenshot of a sample prompt.

Bash

**************************************************
* ATTENTION:                                     *
**************************************************
* the hg_ps1 call in your PS1 only works with    *
* single quotes (')                              *
*                                                *
* (with double quotes (") the variable is only   *
*  evaluated once)                               *
**************************************************

You can modify your ~/.bashrc along following lines:

. ~/mercurialprompt/hgswift.sh
HGS_COLOR_S="\033[0;32m" # green
HGS_COLOR_E="\033[0m"    # reset color
HGS_DISPLAY_MOD=0        # disable modified WD display,
                         # comment this if you are not on Solaris

PS1="${TITLEBAR}"\
'\[\033[0;32m\]\u@\h \t    \[\033[0m\]$(hg_ps1)\n\[\033[0;31m\]\w $ \[\033[0m\]'

Or without colors and no xterm titlebar:

. ~/mercurialprompt/hgswift.sh
PS1='\u@\h \t    $(hg_ps1)
\w $ '

Zsh

**************************************************
* ATTENTION:                                     *
**************************************************
* the hg_ps1 call in your PROMPT only works with *
* single quotes (') and setopt prompt_subst      *
*                                                *
* (with double quotes (") the variable is only   *
*  evaluated once)                               *
**************************************************

You can modify your ~/.zshrc along following lines:

. ~/mercurialprompt/hgswift.sh
HGS_COLOR_S="%{$fg[green]%}"
HGS_COLOR_E="%{$reset_color%}"

setopt prompt_subst
PROMPT='%{$fg[green]%}%n@%m %T %D Exit[%?]    %{$reset_color%}$(hg_ps1)
%{$fg[red]%}%~ $ %{$reset_color%}'

Configuration

There are a few global variables you can set to configure HGSwift. They are listed and explained in the head of hgswift.sh. The previous sections contain examples how to use them.

Overhead

For each prompt the script runs several commands to generate the status. The most expensive commands are hg incoming, hg outgoing and hg id. The results of the first two are cached (by default for 10 minutes inside ~/.hgswiftcache). And by default the commands time out after 4 seconds (you can configure other timeouts).

hg id is not always awfully expensive, only on a slow system (think Slowlaris, the repository and the Python installation are on a slow NFS server). This command is needed to display whether the working directory includes uncommitted changes - you can disable this feature via setting HGS_DISPLAY_MOD=0.

HGSwift is inspired by hg-prompt. hg-prompt is more generic, because it supports many keywords for constructing custom prompts. But it does not provide the default pull location as keyword and it does not include a timeout feature for slow networks/systems. hg-prompt is a Python extension to Mercurial, where HGSwift is a very short and simple shell script.

Feedback

I appreciate feedback and comments:

gsauthof@techfak.uni-bielefeld.de
mail@georg.so