Giter Club home page Giter Club logo

hg_ps1's Introduction

-- markdown --

About __hg_ps1

__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.

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. 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.

Installation

To install, run the setup script:

python setup.py install

This will install the source as an egg in your Python site-packages directory, and put __hg_ps1 into (most likely) /usr/local/bin. (Run python setup.py 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 http://mercurial.berkwood.com/, use /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 <[email protected]> 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

Local branches

zerok has created a fork of __hg_ps1 that provides support for local branches. His repository is here: http://bitbucket.org/zerok/hg_ps1-lbranch/.

hg_ps1's People

Contributors

jezdez avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.