6

I want to create an alias so that when I run:

hg pushbranch <<SOME_BRANCH>>

it aliases to:

hg push -b <<SOME_BRANCH>>

Where SOME_BRANCH is the name of a branch I wish to push. I can create an alias in my .hgrc, but don't know how I could supply an argument to the alias.

Adam Parkin
  • 17,891
  • 17
  • 66
  • 87

2 Answers2

13

From the hgrc help

Positional arguments in the form of $1, $2, etc in the alias definition are expanded by Mercurial before execution.

Thus, your alias definition, which will allow to push any branch, will be

pushbranch = push -b $1

and hg pushbranch mybranch is expanded to hg push -b mybranch

Juan
  • 1,204
  • 1
  • 11
  • 25
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • In the example in the original version of this answer, %1 should be $1, but stackoverflow currently won't take an edit from me less than 6 characters. Please fix. – Juan Jun 06 '17 at 16:44
4

You can simply add the arguments in your alias. Some examples from my configuration:

[alias]
log0 = log -l 10
tipr = tip --template "{node|short}"

If you provide additional arguments, they'll simply be appended. For example, the following will be functionally equivalent to log -l 10 -k Refactoring.

$ hg log0 -k Refactoring
Derek Slager
  • 13,619
  • 3
  • 34
  • 34