All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Fionn via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Felipe Contreras <felipe.contreras@gmail.com>,
	Fionn <git@fionn.email>, Fionn Fitzmaurice <git@fionn.email>
Subject: [PATCH] completion: exclude previous file arguments in Zsh
Date: Sat, 03 Oct 2026 11:22:06 +0000	[thread overview]
Message-ID: <pull.2216.git.git.1791026527023.gitgitgadget@gmail.com> (raw)

From: Fionn Fitzmaurice <git@fionn.email>

When using the _git completion function bundled with Zsh
(https://sf.net/p/zsh/code/ci/master/tree/Completion/Unix/Command/_git),
duplicate files in an argument list will not be offered as completion
candidates.

For example, suppose we have untracked files aa and ab (only). Then with
the Zsh completion,

    git add aa a<tab>

would not offer both aa and ab as completion candidates, rather it would
complete ab only.

This behaviour is not present in git-completion.zsh shipped with Git,
which does not deduplicate arguments.

We can get this with minor changes, however. Here we introduce an array
__git_file_exclude which we populate with existing arguments and then
tell compadd to exclude them, which closely matches the Zsh _git
completion behaviour (as well as common programs such as rm).

Signed-off-by: Fionn Fitzmaurice <git@fionn.email>
---
    completion: exclude previous file arguments in Zsh

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2216%2Ffionn%2Fzsh-completion-exclude-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2216/fionn/zsh-completion-exclude-v1
Pull-Request: https://github.com/git/git/pull/2216

 contrib/completion/git-completion.zsh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index d5c526665b..26444923c1 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -117,7 +117,7 @@ __gitcomp_file ()
 	emulate -L zsh
 
 	compset -P '*[=:]'
-	compadd -f -p "${2-}" -- ${(f)1} && _ret=0
+	compadd -f -p "${2-}" -F __git_file_exclude -- ${(f)1} && _ret=0
 }
 
 __gitcomp_direct_append ()
@@ -284,6 +284,8 @@ __git_zsh_main ()
 
 		(( $+opt_args[--help] )) && command='help'
 
+		__git_file_exclude=(${words[2,-1]:#${words[CURRENT]}})
+
 		words=( ${orig_words[@]} )
 
 		__git_zsh_bash_func $command
@@ -296,6 +298,7 @@ _git ()
 	local _ret=1
 	local cur cword prev
 	local __git_repo_path
+	local -a __git_file_exclude
 
 	cur=${words[CURRENT]}
 	prev=${words[CURRENT-1]}

base-commit: c46c1e37724f0478939de636ab8ea5a89086d532
-- 
gitgitgadget

             reply	other threads:[~2026-10-03 11:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-03 11:22 Fionn via GitGitGadget [this message]
2026-10-04  8:07 ` [PATCH] completion: exclude previous file arguments in Zsh SZEDER Gábor
2026-10-04 16:17   ` Fionn
2026-10-04 21:13   ` Junio C Hamano
2026-10-05  1:44     ` Fionn

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=pull.2216.git.git.1791026527023.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=felipe.contreras@gmail.com \
    --cc=git@fionn.email \
    --cc=git@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.