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

Re: [PATCH 3/5] completion: fix Zsh handling of stash names

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 16, 2026, 08:01 UTC
Message-ID
<atHZvexnI0Ia7Xjr@pks.im>
In-Reply-To
<3d1cd00dd8456aeaf8259767d9e33b7421aef9c4.1791827304.git.ben.knoble@gmail.com>
On Mon, Oct 12, 2026 at 01:48:29PM -0400, D. Ben Knoble wrote:
Show 14 quoted lines
> 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 things we're trying to do a brace expansion, I
s/things/thinks/
Show 19 quoted lines
> 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 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.

Hm. I assume you tried finding a variant that works for both Bash and Zsh so that we don't have to carry this override?

Show 12 quoted lines
> 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
> +}
Patrick
Previous: D. Ben KnobleNext: Ben Knoble
Message 7 of 28 in “stash completion miscellany”
  1. 0/5 stash completion miscellanyD. Ben Knoble, Oct 12, 2026
  2. 1/5 completion: simplify stash subcommand completionD. Ben Knoble, Oct 12, 2026
  3. Patrick SteinhardtOct 16, 2026
  4. Ben KnobleOct 19, 2026
  5. 2/5 completion: extract common stash listing codeD. Ben Knoble, Oct 12, 2026
  6. 3/5 completion: fix Zsh handling of stash namesD. Ben Knoble, Oct 12, 2026
  7. Patrick SteinhardtOct 16, 2026
  8. Ben KnobleOct 19, 2026
  9. 4/5 doc: drop usage mentions of "git stash save"D. Ben Knoble, Oct 12, 2026
  10. Patrick SteinhardtOct 16, 2026
  11. 5/5 completion: drop "stash save" completion altogetherD. Ben Knoble, Oct 12, 2026
  12. Patrick SteinhardtOct 16, 2026
  13. Ben KnobleOct 19, 2026
  14. Patrick SteinhardtOct 20, 2026
  15. D. Ben KnobleOct 22, 2026
  16. Patrick SteinhardtOct 23, 2026
  17. 0/5 stash completion miscellanyD. Ben Knoble, Oct 23, 2026
  18. 1/5 completion: simplify stash subcommand completionD. Ben Knoble, Oct 23, 2026
  19. 2/5 Completion: extract common stash listing codeD. Ben Knoble, Oct 23, 2026
  20. Junio C HamanoOct 23, 2026
  21. 3/5 completion: fix Zsh handling of stash namesD. Ben Knoble, Oct 23, 2026
  22. 4/5 doc: drop usage mentions of "git stash save"D. Ben Knoble, Oct 23, 2026
  23. 5/5 completion: drop "stash save" completion altogetherD. Ben Knoble, Oct 23, 2026
  24. Junio C HamanoOct 23, 2026
  25. Ben KnobleOct 23, 2026
  26. Kristoffer HaugsbakkOct 23, 2026
  27. Patrick SteinhardtOct 26, 2026
  28. Junio C HamanoOct 26, 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.