[Bug 5867] New: allow default values for alias arguments

mercurial-bugs at mercurial-scm.org mercurial-bugs at mercurial-scm.org
Thu May 3 14:27:53 EDT 2018


https://bz.mercurial-scm.org/show_bug.cgi?id=5867

            Bug ID: 5867
           Summary: allow default values for alias arguments
           Product: Mercurial
           Version: 4.4.1
          Hardware: PC
                OS: Linux
            Status: UNCONFIRMED
          Severity: feature
          Priority: wish
         Component: Mercurial
          Assignee: bugzilla at mercurial-scm.org
          Reporter: sphink at gmail.com
                CC: mercurial-devel at mercurial-scm.org

Example: in my [aliases], I have things like

    booktotopic = topics $1 -r 'allbook($1)'

now say I wanted the option to name the topic differently from the bookmark. I
could do

    booktotopic2 = topics $2 -r 'allbook($1)'

but really I want something like the shell's

    booktotopic = topics ${2:-$1} -r 'allbook($1)'

Even more commonly, I want to default to the '.' revision in various aliases.
Right now, I do workarounds like

    ls = ![[ -n "$1" ]] && r="$1" || r=.; $HG log ...$r...

(I can't just do !r="${:-1}" because $1 is considered to be set but empty.)

I'd really rather not spawn a subshell at all, especially since that results in
paying for hg startup twice. I'm not sure what syntax to suggest; I guess
${1:-default} would work, but it's pretty cryptic. Perhaps

    [alias]
    booktotopic($1,$2=$1) = topics "$2" -r 'allbook($1)'

? (Though that may imply that booktotopic(bname,tname=$bname) ought to work,
and that feels like a more extreme change -- do you use $bname in the alias
then? Or require parameters to start with '$'?)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Mercurial-devel mailing list