RFC: Shell Aliases and Arguments

Steve Losh steve at dumbwaiterdesign.com
Sun Aug 22 14:46:34 CDT 2010


On Aug 22, 2010, at 4:46 AM, Isaac Jurado wrote:

> Replying Steve Losh:
>> 
>> Sure, here's a few from my current ~/.hgrc.  I'm sure I'll come up
>> with more once over time:
> 
> Well, this is a bit contradictory.  So while mercurial does not provide
> any configuration interface and lets the task to a text editor (which,
> for the record, I find completely reasonable); it can, however,
> partially reimplement and/or replace traditional shell scripts.

This is not a new concept -- you can already do this with vanilla Mercurial 1.6 (and probably earlier) using hooks:

    [alias]
    # Define an alias that does nothing.
    # The pre-[alias] hook has the real functionality.
    qempty = status --change null
    
    [hooks]
    pre-qempty = $HG qrefresh -X "`$HG root`"

Doing it like this works, but it's ugly.  The alias and definition are split apart in the hgrc file and it's a pain to work with  arguments (you can use `cut` if you need to though).

These shell alias patches just make it easier to create these aliases.  They don't add any new concepts/functionality to the hgrc file.

> 
> I'm not a crew member nor a frequent contributor, therefore there's very
> little I can do.  But I still can't find the ratinale behind this, other
> than how cool it is to run "hg mkrepo".

mkrepo is just me being lazy.  A better example is the "qempty" alias I sent.  Sure, you could type "hg qref -X ." all the time, but it's annoying.

It's also more dangerous, because at some point you're probably going to be cd'ed somewhere inside the repo.  Running "hg qref -X ." when you're not at the root doesn't empty the patch any more.  Hopefully you'd figure out that you made a mistake before you went too much further, but creating a "qempty" alias is much easier than trying to fix things after you've run something you didn't mean to run out of habit.

You could of course make an 'hgqempty' script and put it on your path.  That works, but it's less than ideal:

* It pollutes the tab completion namespace.
* When you want to run an alias/script you now need to think "Did I define that as an alias (hg qempty) or a script (hgqempty)?"
* It's yet another file to keep synced to all the machines you work on (not a huge deal, since it could live with the rest of your dotfiles).

Defining qempty as an alias avoids these problems.

> 
> And, again, with all my respects.
> 
> Regards.
> 
> -- 
> Isaac Jurado
> 
> "The noblest pleasure is the joy of understanding."
>                                  Leonardo da Vinci
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list