4

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
  • 16,485
  • 16
  • 62
  • 85

2 Answers2

11

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
  • 904
  • 1
  • 7
  • 23
Lazy Badger
  • 91,325
  • 7
  • 76
  • 105
  • 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
3

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,021
  • 3
  • 32
  • 34