From: "Lutz Lengemann" <lutz@lengemann.net>
To: "D. Ben Knoble" <ben.knoble@gmail.com>,
"Lutz Lengemann" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>
Subject: Re: [PATCH] completion: zsh: support completion after "git -C <path>"
Date: Mon, 17 Aug 2026 21:29:05 +0200 [thread overview]
Message-ID: <a6a9fe7c-e46d-462f-b3b0-7ae6c2d52fe4@app.fastmail.com> (raw)
In-Reply-To: <CALnO6CB1vJ7RtBzTUSJSfYtfH+W2MZCFEkqNWeBXbWJ2r3Pdyg@mail.gmail.com>
Hi Ben
(Resending, my earlier reply was rejected by the list for being HTML.)
On Wed, Jul 15, 2026, at 00:34, D. Ben Knoble wrote:
> Any progress here? I just found my local copy of this patch and was
> briefly surprised to see it hadn't graduated anywhere (until I
> realized conversation had stalled at this point).
Sorry for the very late reply, I was on holiday and then other life
things got in the way of answering :( I do have a v2 ready, which I
have just pushed to my fork, and which follows this message.
Junio C Hamano <gitster@pobox.com> writes:
> Doesn't it want to do something similar to what __git_main in
> git-completion.bash does at the beginning, namely, this part?
It does, thanks. v2 no longer skips only leading -C options, but walks
the words in front of the command and skips over the global options and,
where they take one, their arguments, like __git_main does.
That also makes "git -p checkout <TAB>" and "git --git-dir=<path>
checkout <TAB>" complete the arguments of the command, which they did
not before.
Two related gaps are left alone, as they are bugs in the _arguments
specification rather than in the command lookup: -c is not listed there
at all, and --git-dir and friends are spelled "--git-dir=-", which
accepts only "--git-dir=<path>", not the "--git-dir <path>" form. I can
send patches for those separately.
"D. Ben Knoble" <ben.knoble@gmail.com> writes:
> But we mark these local, so how do they propagate to the other
> functions?
zsh scoping is dynamic, not lexical, so a variable declared "local" in
__git_zsh_main is visible in the functions that are called from it, the
bash helpers included. That is how __git_dir and __git_cmd_idx are
handed down already, and __git_C_args works the same way.
> We should probably note in the log message that the _directories
> completion will not account for previous -C
I added a note about this in the log message.
> I think we could do _slightly_ better by using a state "->dir" or
> something, accumulating the current prefix, and passing that to
> _directories as a prefix with -W
I tried that and it works, but it changes what -C offers, which is more
than fixing the completion after -C, so I left it out; happy to send it
on top. Two things to watch out for there: the accumulated path has to
be made absolute, as -W with ".." gave me the directories of "/", and
the accumulation has to stop before the word that is being completed.
> By the way, I've realized that "git -<tab>" has the same problem (a
> giant list of files after the other option completions)
That one is older than this patch: the file listing comes from the
fallback at the end of _git,
let _ret && _default && _ret=0
which is where the "use-compctl" and "globbed-files" tags in your
_complete_help dump come from. I could not reproduce the repeated
description block with "zsh -f" and only the _complete completer, so
something in my setup or yours may differ there. Either way it wants
its own topic.
I hope that the change now looks good, and if there is anything I should
still look at just tell me.
Thank you very much
Lutz
prev parent reply other threads:[~2026-08-17 19:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 15:30 [PATCH] completion: zsh: support completion after "git -C <path>" Lutz Lengemann via GitGitGadget
2026-06-17 17:17 ` Ben Knoble
2026-06-17 17:21 ` Junio C Hamano
2026-06-18 17:43 ` D. Ben Knoble
2026-07-14 22:34 ` D. Ben Knoble
2026-08-17 19:29 ` Lutz Lengemann [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a6a9fe7c-e46d-462f-b3b0-7ae6c2d52fe4@app.fastmail.com \
--to=lutz@lengemann.net \
--cc=ben.knoble@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox