git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH RFC] completion: add support for completing email aliases

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Nov 14, 2015, 09:44 UTC
Message-ID
<20151114104402.Horde.1et7Ak3QVluviq1iADQupQI@webmail.informatik.kit.edu>
In-Reply-To
<CA+P7+xpxpkCJxesU4Tif46pYeQHG-NdvMuD0bj1Kr_kGz4djTg@mail.gmail.com>
Quoting Jacob Keller <jacob.keller@gmail.com>:
> On Fri, Nov 13, 2015 at 4:55 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:
Show 15 quoted lines
>> However, 'git send-email' already knows how to parse these files, so
>> how about letting it do all the work, i.e. teach it a new 'git
>> send-email --list-aliases' option that would only read the config,
>> parse the alias file, print all the aliases, i.e. the keys from the
>> 'aliases' associative array and exit.  That way we wouldn't have to
>> duplicate parts of an already working and tested parsing into a
>> different language, the completion script would be simpler, because we
>> wouldn't need __git_email_aliases() helper function, it would
>> immediately benefit from future bug fixes to 'send-email', and new
>> alias file formats would Just Work.
>>
>
> Agreed. I hadn't thought about it this way. We could also add email
> addresses to the complete list, if that was a reasonable addition?
> Maybe not worth it though.
I don't really see the use case of listing email addresses as well.
> I'll respin a version like this in the next few days.
Great, thank you!
Show 33 quoted lines
>>> @@ -1735,6 +1786,24 @@ _git_send_email ()
>>>                         " "" "${cur##--thread=}"
>>>                 return
>>>                 ;;
>>> +       --to=*)
>>> +               __gitcomp "
>>> +               $(__git_email_aliases)
>>> +               " "" "${cur##--to=}"
>>> +               return
>>> +               ;;
>>> +       --cc=*)
>>> +               __gitcomp "
>>> +               $(__git_email_aliases)
>>> +               " "" "${cur##--cc=}"
>>> +               return
>>> +               ;;
>>> +       --bcc=*)
>>> +               __gitcomp "
>>> +               $(__git_email_aliases)
>>> +               " "" "${cur##--bcc=}"
>>> +               return
>>> +               ;;
>>
>>
>> These case branches look essentially the same except what has to be
>> removed from the word being completed.  And what gets removed is
>> essentially everything before and including the first '='.
>> So how about squashing these three cases into a single (untested) one
>> like this:
>
> I tried this, but I wasn't sure if it was reasonable or not inccase
> there was an equals later in the section? since glob will match the
> longest one?

That's why I used a single '#' in the parameter expansion below. A single '#' removes the shortest matching prefix pattern, '##' removes the longest:

$ cur="foo=bar=baz" $ echo "#: ${cur#*=} ##: ${cur##*=}" #: bar=baz ##: baz

(Don't ask why we use '##' without glob everywhere... :)
Show 7 quoted lines
>>
>>      --to=*|--cc=*|--bcc=*)
>>        __gitcomp "$(__git_email_aliases)" "" "${cur#*=}"
>>        return
>>
>>        ;;
>>

There's an other point: these options have an unstuck variant as well, i.e. '--to alice'. It would be great to support those, too. Perhaps something like this snippet looking at the previous word on the command line could come before the big case statement handling the current word:

   case "$prev" in
   --to|--cc|--bcc)
     __gitcomp "$(git --git-dir="$dir" send-email --list-aliases 2>/dev/null)"
     return
     ;;
   esca
Previous: Jacob Keller
Message 3 of 3 in “Re: [PATCH RFC] completion: add support for completing email aliases”
  1. SZEDER GáborNov 14, 2015
  2. Jacob KellerNov 14, 2015
  3. SZEDER GáborNov 14, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.