Patchwork bashcompletion: show available command-line switches for aliases

login
register
mail settings
Submitter Martijn Pieters
Date June 21, 2016, 4:17 p.m.
Message ID <5931a36ea0d7bbc14d6e.1466525825@mjpieters-mbp>
Download mbox | patch
Permalink /patch/15565/
State Accepted
Headers show

Comments

Martijn Pieters - June 21, 2016, 4:17 p.m.
# HG changeset patch
# User Martijn Pieters <mjpieters@fb.com>
# Date 1466525751 -3600
#      Tue Jun 21 17:15:51 2016 +0100
# Node ID 5931a36ea0d7bbc14d6e68eb69b4fc81b2e00e97
# Parent  fcaf20175b1b05aa753e1b9f65f10d35a86224df
bashcompletion: show available command-line switches for aliases

When auto-completing hg commands, aliases are listed, but not the available
switches for an alias, because `HGPLAIN=1` filters these out. Add a
`HGPLAINEXCEPT=alias` exception to resolve this.

We make heavy use of aliases that drive hg log with custom revsets, sorting and
the -G switch, but want our users to be able to auto-complete any additional
command-line switches.
Anton Shestakov - June 21, 2016, 4:36 p.m.
22.06.2016, 00:18, "Martijn Pieters" <mj@zopatista.com>:
>  # HG changeset patch
>  # User Martijn Pieters <mjpieters@fb.com>
>  # Date 1466525751 -3600
>  # Tue Jun 21 17:15:51 2016 +0100
>  # Node ID 5931a36ea0d7bbc14d6e68eb69b4fc81b2e00e97
>  # Parent fcaf20175b1b05aa753e1b9f65f10d35a86224df
>  bashcompletion: show available command-line switches for aliases
>
>  When auto-completing hg commands, aliases are listed, but not the available
>  switches for an alias, because `HGPLAIN=1` filters these out. Add a
>  `HGPLAINEXCEPT=alias` exception to resolve this.
>
>  We make heavy use of aliases that drive hg log with custom revsets, sorting and
>  the -G switch, but want our users to be able to auto-complete any additional
>  command-line switches.
>
>  diff --git a/contrib/bash_completion b/contrib/bash_completion
>  --- a/contrib/bash_completion
>  +++ b/contrib/bash_completion
>  @@ -184,7 +184,7 @@
>               return
>           fi
>
>  - opts=$(_hg_cmd debugcomplete --options "$cmd")
>  + opts=$(HGPLAINEXCEPT=alias _hg_cmd debugcomplete --options "$cmd")

Looks good, since another instance of "_hg_cmd debugcomplete" already has HGPLAINEXCEPT=alias.

JFYI, I've tried this with my "crecord = !$HG commit --interactive --config ui.interface=curses $@" alias and since `hg debugcomplete --options crecord` only lists global options, it still couldn't complete --amend or --secret...
Martijn Pieters - June 21, 2016, 9:33 p.m.
On 21 Jun 2016, at 17:36, Anton Shestakov <engored@ya.ru> wrote:
> 22.06.2016, 00:18, "Martijn Pieters" <mj@zopatista.com>:
>> # HG changeset patch
>> # User Martijn Pieters <mjpieters@fb.com>
>> # Date 1466525751 -3600
>> # Tue Jun 21 17:15:51 2016 +0100
>> # Node ID 5931a36ea0d7bbc14d6e68eb69b4fc81b2e00e97
>> # Parent fcaf20175b1b05aa753e1b9f65f10d35a86224df
>> bashcompletion: show available command-line switches for aliases
>> 
>> When auto-completing hg commands, aliases are listed, but not the available
>> switches for an alias, because `HGPLAIN=1` filters these out. Add a
>> `HGPLAINEXCEPT=alias` exception to resolve this.
>> 
>> We make heavy use of aliases that drive hg log with custom revsets, sorting and
>> the -G switch, but want our users to be able to auto-complete any additional
>> command-line switches.
>> 
>> diff --git a/contrib/bash_completion b/contrib/bash_completion
>> --- a/contrib/bash_completion
>> +++ b/contrib/bash_completion
>> @@ -184,7 +184,7 @@
>>              return
>>          fi
>> 
>> - opts=$(_hg_cmd debugcomplete --options "$cmd")
>> + opts=$(HGPLAINEXCEPT=alias _hg_cmd debugcomplete --options "$cmd")
> 
> Looks good, since another instance of "_hg_cmd debugcomplete" already has HGPLAINEXCEPT=alias.
> 
> JFYI, I've tried this with my "crecord = !$HG commit --interactive --config ui.interface=curses $@" alias and since `hg debugcomplete --options crecord` only lists global options, it still couldn't complete --amend or --secret...

Unfortunately, that's a shell alias you have there, which can't be expanded to the original hg command as hg can't be expected to run the shell script you specify to try and extract it. That use-case will have to remain out of reach (as it is now).

It's a pity `--config` is not supported in straight-up aliases, otherwise you could've dropped the !$HG prefix.

Martijn
Sean Farley - June 21, 2016, 10:15 p.m.
Martijn Pieters <mj@zopatista.com> writes:

> # HG changeset patch
> # User Martijn Pieters <mjpieters@fb.com>
> # Date 1466525751 -3600
> #      Tue Jun 21 17:15:51 2016 +0100
> # Node ID 5931a36ea0d7bbc14d6e68eb69b4fc81b2e00e97
> # Parent  fcaf20175b1b05aa753e1b9f65f10d35a86224df
> bashcompletion: show available command-line switches for aliases
>
> When auto-completing hg commands, aliases are listed, but not the available
> switches for an alias, because `HGPLAIN=1` filters these out. Add a
> `HGPLAINEXCEPT=alias` exception to resolve this.
>
> We make heavy use of aliases that drive hg log with custom revsets, sorting and
> the -G switch, but want our users to be able to auto-complete any additional
> command-line switches.
>
> diff --git a/contrib/bash_completion b/contrib/bash_completion
> --- a/contrib/bash_completion
> +++ b/contrib/bash_completion
> @@ -184,7 +184,7 @@
>              return
>          fi
>  
> -        opts=$(_hg_cmd debugcomplete --options "$cmd")
> +        opts=$(HGPLAINEXCEPT=alias _hg_cmd debugcomplete --options "$cmd")

Looks good to me as well.
Sean Farley - June 21, 2016, 10:17 p.m.
Martijn Pieters <mj@zopatista.com> writes:

> [ Unknown signature status ]
> On 21 Jun 2016, at 17:36, Anton Shestakov <engored@ya.ru> wrote:
>> 22.06.2016, 00:18, "Martijn Pieters" <mj@zopatista.com>:
>>> # HG changeset patch
>>> # User Martijn Pieters <mjpieters@fb.com>
>>> # Date 1466525751 -3600
>>> # Tue Jun 21 17:15:51 2016 +0100
>>> # Node ID 5931a36ea0d7bbc14d6e68eb69b4fc81b2e00e97
>>> # Parent fcaf20175b1b05aa753e1b9f65f10d35a86224df
>>> bashcompletion: show available command-line switches for aliases
>>> 
>>> When auto-completing hg commands, aliases are listed, but not the available
>>> switches for an alias, because `HGPLAIN=1` filters these out. Add a
>>> `HGPLAINEXCEPT=alias` exception to resolve this.
>>> 
>>> We make heavy use of aliases that drive hg log with custom revsets, sorting and
>>> the -G switch, but want our users to be able to auto-complete any additional
>>> command-line switches.
>>> 
>>> diff --git a/contrib/bash_completion b/contrib/bash_completion
>>> --- a/contrib/bash_completion
>>> +++ b/contrib/bash_completion
>>> @@ -184,7 +184,7 @@
>>>              return
>>>          fi
>>> 
>>> - opts=$(_hg_cmd debugcomplete --options "$cmd")
>>> + opts=$(HGPLAINEXCEPT=alias _hg_cmd debugcomplete --options "$cmd")
>> 
>> Looks good, since another instance of "_hg_cmd debugcomplete" already has HGPLAINEXCEPT=alias.
>> 
>> JFYI, I've tried this with my "crecord = !$HG commit --interactive --config ui.interface=curses $@" alias and since `hg debugcomplete --options crecord` only lists global options, it still couldn't complete --amend or --secret...
>
> Unfortunately, that's a shell alias you have there, which can't be expanded to the original hg command as hg can't be expected to run the shell script you specify to try and extract it. That use-case will have to remain out of reach (as it is now).
>
> It's a pity `--config` is not supported in straight-up aliases, otherwise you could've dropped the !$HG prefix.

I was hoping Yuya would one day fix this (help us, Obi Wan Nishihara,
you're our only hope).
Matt Mackall - June 22, 2016, 6:45 p.m.
On Tue, 2016-06-21 at 17:17 +0100, Martijn Pieters wrote:
> # HG changeset patch
> # User Martijn Pieters <mjpieters@fb.com>
> # Date 1466525751 -3600
> #      Tue Jun 21 17:15:51 2016 +0100
> # Node ID 5931a36ea0d7bbc14d6e68eb69b4fc81b2e00e97
> # Parent  fcaf20175b1b05aa753e1b9f65f10d35a86224df
> bashcompletion: show available command-line switches for aliases

Queued for default, thanks.

-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/contrib/bash_completion b/contrib/bash_completion
--- a/contrib/bash_completion
+++ b/contrib/bash_completion
@@ -184,7 +184,7 @@ 
             return
         fi
 
-        opts=$(_hg_cmd debugcomplete --options "$cmd")
+        opts=$(HGPLAINEXCEPT=alias _hg_cmd debugcomplete --options "$cmd")
 
         COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
         _hg_fix_wordlist