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

Re: [PATCH] completion: exclude previous file arguments in Zsh

From
FFionn <fionn@fionn.email>
Date
Oct 4, 2026, 16:17 UTC
Message-ID
<DLW6TDPQ9DA8.3CY39XL14GO9E@fionn.email>
In-Reply-To
<asIJO3CZ/P/2L4qi@szeder.dev>
> "existing arguments" of what?
Of a subcommand that takes paths.
> I don't do Zsh, but that 2 as index looks suspicious.

Fair to be suspicious. word[1] is the subcommand (e.g. "add"), so we index from 2 on in order to skip it. This is independent of where the subcommand appears in the entire command line.

Show 7 quoted lines
> What will be excluded in the following command line:
>
>   git -C dir -C subdir -c foo.bar=baz add file1 file2 <TAB>
>
> I think we should exclude only those arguments that come after the git
> command, in this case after "add", i.e. "file1" and "file2", but I
> suspect that everything starting with "dir" will get excluded.

In my testing this works correctly (i.e. file1 and file2 are not offered as completion candidates any more, but if e.g. dir or foo exist in the subdirectory, they would be offered).

I've been dogfooding this for about 8 months on and off. Occasionally completion candidates I'd hope would be excluded are present, but this is because the fallback completion bypasses __gitcomp_file, which is a separate issue. I have not yet encountered completion candidates being unexpectedly excluded.

An easy way to test this is to link git-completion.zsh to _git and then add

    fpath=(/path/to/directory/containing/_git/file $fpath[@])
to ~/.zshrc, or similar.
Previous: SZEDER GáborNext: Junio C Hamano
Message 3 of 5 in “completion: exclude previous file arguments in Zsh”
  1. completion: exclude previous file arguments in ZshFionn via GitGitGadget, Oct 3, 2026
  2. SZEDER GáborOct 4, 2026
  3. FionnOct 4, 2026
  4. Junio C HamanoOct 4, 2026
  5. FionnOct 5, 2026

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.