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

Re: [PATCH] completion: zsh: trivial improvement

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Jun 8, 2021, 05:37 UTC
Message-ID
<60bf0217e0a90_198bd720828@natae.notmuch>
In-Reply-To
<20210608050115.GC6312@szeder.dev>
SZEDER Gábor wrote:
Show 10 quoted lines
> On Mon, Jun 07, 2021 at 09:38:07PM -0500, Felipe Contreras wrote:
> > $words has basically all the words we need, except the first one: git.
> > 
> > Lets simply add that instead of passing the original, which contains
> > options we don't want to pass downstream (like --git-dir).
> 
> In our Bash completion script $words contains all words of the current
> command on the command line, including 'git -C tmp -c foo.bar=baz'.
> 
> Why should zsh completion behave differently?

Because we use the _arguments function [1]. It changes the $words array and removes all the arguments it was able to parse. All that remains is that which it didn't understand.

If you do:
  git --git-dir=x show --<tab>

_arguments will remove 'git --git-dir=x'. And there is no point in passing '--git-dir=x' to _git_show. It provides no useful information, and it was already processed by __git_zsh_main and __git_dir is set.

__git_main doesn't need to change $words, but it does increase __git_cmd_idx to match the position of the command.

But since in the zsh case _argments already modified $words, we can just add 'git' to the start and always use __git_cmd_idx=1.

[1] https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Completion-Functions
-- 
Felipe Contreras
Previous: SZEDER Gábor
Message 3 of 3 in “completion: zsh: trivial improvement”
  1. completion: zsh: trivial improvementFelipe Contreras, Jun 8, 2021
  2. SZEDER GáborJun 8, 2021
  3. Felipe ContrerasJun 8, 2021

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.