hg-prompt /

Filename Size Date modified Message
19 B
2.5 KB
2.6 KB
-*- markdown -*-

hg-prompt
=========

hg-prompt is a Mercurial extension which adds an 'hg prompt' command for putting repository information into a shell prompt efficiently.

Installing
----------

Clone the repository:

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

Edit the `[extensions]` section in your `~/.hgrc` file:

    :::text
    [extensions]
    prompt = (path to)/hg-prompt/prompt.py

Using the Command
-----------------

The `hg prompt` command takes a single string as an argument and outputs it.  Here's a simple (and useless) example:

    :::text
    $ hg prompt "test"
    test

Keywords in curly braces can be used to output repository information:

    :::text
    $ hg prompt "currently on {branch}"
    currently on default

Keywords also have an extended form:

    :::text
    {optional text{branch}more optional text}

This form will output the text and the expanded keyword **only** if the keyword successfully expands.  This can be useful for displaying extra text only if it's applicable:

    :::text
    $ hg prompt "currently on {branch} and at {bookmark}"
    currently on branch default and at 
    
    $ hg prompt "currently on {branch} {and at {bookmark}}"
    currently on branch default 
    
    $ hg bookmark my-book
    
    $ hg prompt "currently on {branch} {and at {bookmark}}"
    currently on branch default and at my-book

Available Keywords
------------------

There are only a few keywords at the moment (mostly the ones I want for myself).  If you have any suggestions for more please let me know.

* bookmark: the current bookmark
* branch: the current branch
* status:
    * `!` if the repository has any changed, added, removed or deleted files, otherwise
    * `?` if the repository has any untracked (but not ignored) files, otherwise
    * nothing

Putting it in a Bash Prompt
---------------------------

To put it in your bash prompt, edit your `~/.bashrc` file to include something like this:

    #!bash
    hg_ps1() {
        hg prompt "{ on {branch}}{ at {bookmark}}{status}" 2> /dev/null
    }
    
    export PS1='\u at \h in \w$(hg_ps1) $ '

`source ~/.bashrc` after to test it out.  Make sure you're in a Mercurial repository or you won't see anything.

Questions, Comments, Suggestions
--------------------------------

The code was kind of thrown together in one night after I got tired of chaining three or four hg runs together to get what I wanted.  I'm sure it's not perfect, so if you've got a way to improve it please add and issue and let me know.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.