Git development
 help / color / mirror / Atom feed
From: "D. Ben Knoble" <ben.knoble@gmail.com>
To: git@vger.kernel.org
Cc: "D. Ben Knoble" <ben.knoble@gmail.com>,
	Patrick Steinhardt <ps@pks.im>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 3/5] completion: fix Zsh handling of stash names
Date: Fri, 23 Oct 2026 09:20:53 -0400	[thread overview]
Message-ID: <f4f6b89ff6584e3d5dcc8a0ade81e05d3203a55f.1792761643.git.ben.knoble@gmail.com> (raw)
In-Reply-To: <cover.1792761643.git.ben.knoble@gmail.com>

When Git completes stashes for Zsh, it eventually invokes something like
this (via our redefinition of __gitcomp_nl):

    compadd -Q -S " " -p "" -- 'stash@{0}' 'stash@{1}' && _ret=0

Because of -Q, the braces are unquoted, and Zsh will leave us at (for
example)

    git stash show stash@{
                   cursor ^

From here, the list-choices widget (on Ctrl-D by default) will show
stash@{0} and stash@{1}, but the complete-word widget (Tab) will just
add another brace. Zsh thinks we're trying to do a brace expansion, I
think! Interestingly, using menu-complete (Ctrl-N) does cycle through
matches, since it's taking a slightly different completion path in Zsh.

We might try to fix this by passing surrounding single quotes (using the
-S/-p arguments of compadd, which we can do from Bash in our code via
__gitcomp_nl's other parameters), and indeed Zsh will generate

    git stash show 'stash@{
                    cursor ^

but completing here won't find anything, and I'm not totally sure why.

Instead, though, we can let Zsh quote metacharacters (removing -Q) and
everything "just works." It changes the output format a bit (users see
stash@\{0\}, for example), but I find this an improvement over not being
able to complete names at all. menu-complete is unchanged aside from the
extra backslashes.

So, override stash listing completion in Zsh with a working version.

Signed-off-by: D. Ben Knoble <ben.knoble@gmail.com>
---
 contrib/completion/git-completion.zsh | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index d5c526665b..2aea7770d2 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -135,6 +135,11 @@ __gitcomp_file_direct ()
 	__gitcomp_file "$1" ""
 }
 
+__git_complete_stashes ()
+{
+	compadd -S ' ' -- ${(f)"$(__git stash list | sed -n -e 's/:.*//p')"} && _ret=0
+}
+
 _git_zsh ()
 {
 	__gitcomp "v1.1"
-- 
2.56.0.237.g5414b88716.dirty


  parent reply	other threads:[~2026-10-23 13:28 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 17:48 [PATCH 0/5] stash completion miscellany D. Ben Knoble
2026-10-12 17:48 ` [PATCH 1/5] completion: simplify stash subcommand completion D. Ben Knoble
2026-10-16  8:01   ` Patrick Steinhardt
2026-10-19 19:58     ` Ben Knoble
2026-10-12 17:48 ` [PATCH 2/5] completion: extract common stash listing code D. Ben Knoble
2026-10-12 17:48 ` [PATCH 3/5] completion: fix Zsh handling of stash names D. Ben Knoble
2026-10-16  8:01   ` Patrick Steinhardt
2026-10-19 19:56     ` Ben Knoble
2026-10-12 17:48 ` [PATCH 4/5] doc: drop usage mentions of "git stash save" D. Ben Knoble
2026-10-16  8:01   ` Patrick Steinhardt
2026-10-12 17:48 ` [PATCH 5/5] completion: drop "stash save" completion altogether D. Ben Knoble
2026-10-16  8:01   ` Patrick Steinhardt
2026-10-19 20:01     ` Ben Knoble
2026-10-20  6:05       ` Patrick Steinhardt
2026-10-22 13:14         ` D. Ben Knoble
2026-10-23  6:21           ` Patrick Steinhardt
2026-10-23 13:20 ` [PATCH v2 0/5] stash completion miscellany D. Ben Knoble
2026-10-23 13:20   ` [PATCH v2 1/5] completion: simplify stash subcommand completion D. Ben Knoble
2026-10-23 13:20   ` [PATCH v2 2/5] Completion: extract common stash listing code D. Ben Knoble
2026-10-23 17:06     ` Junio C Hamano
2026-10-23 13:20   ` D. Ben Knoble [this message]
2026-10-23 13:20   ` [PATCH v2 4/5] doc: drop usage mentions of "git stash save" D. Ben Knoble
2026-10-23 13:20   ` [PATCH v2 5/5] completion: drop "stash save" completion altogether D. Ben Knoble
2026-10-23 17:06     ` Junio C Hamano
2026-10-23 18:07       ` Ben Knoble
2026-10-23 14:33   ` [PATCH v2 0/5] stash completion miscellany Kristoffer Haugsbakk
2026-10-26  8:48   ` Patrick Steinhardt
2026-10-26 14:30     ` Junio C Hamano

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=f4f6b89ff6584e3d5dcc8a0ade81e05d3203a55f.1792761643.git.ben.knoble@gmail.com \
    --to=ben.knoble@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ps@pks.im \
    /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