threads / patch / 64528

patchAdd completion for short options

Subject: [PATCH] Add completion for short options

## tl;dr

7 messages between Nov 25, 2025 and Dec 7, 2025. Diffs are folded; open one to read it.

replies: 6people: 3as markdown or json

Wiktor Mis via GitGitGadget· Nov 25, 2025, 06:38 UTC · lore
From: Wiktor Mis <mwiktor023@gmail.com>
Git provided completion for long options but not the short ones
Signed-off-by: Wiktor Mis <mwiktor023@gmail.com>
---
    Add completion for short options
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2100%2FWiktorro%2Fpatch-3-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2100/Wiktorro/patch-3-v1
Pull-Request: https://github.com/git/git/pull/2100
 contrib/completion/git-completion.bash | 10 ++++++++++
 1 file changed, 10 insertions(+)
Show changes to contrib/completion/git-completion.bash +10 −0
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 73abea31b4..3f1d6c0955 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3916,6 +3916,16 @@ __git_main ()
 			--help
 			"
 			;;
+		-*)
+			__gitcomp "
+			-C
+			-P
+			-c
+			-h
+			-p
+			-v
+			"
+			;;
 		*)
 			if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
 			then

base-commit: fd372d9b1a69a01a676398882bbe3840bf51fe72
-- 
gitgitgadget
Junio C Hamano· Nov 25, 2025, 16:42 UTC · re: Wiktor Mis via GitGitGadget · lore

Re: [PATCH] Add completion for short options

"Wiktor Mis via GitGitGadget" <gitgitgadget@gmail.com> writes:

As the large part of the completion script is about completing git subcommands and options to these subcommands, it seems that nobody noticed the lack of completion for options of "git" itself.

> Subject: Re: [PATCH] Add completion for short options

This title makes it appear much broader than what the patch does, which is to complete "git -<TAB>" with short options for the "git" potty.

    Subjct: [PATCH] completion: complete "git -<TAB>" with short options
perhaps.
> From: Wiktor Mis <mwiktor023@gmail.com>
>
> Git provided completion for long options but not the short ones
Complete the sentence with something like
    ... not the short ones for "git" itself.
Show 29 quoted lines
> Signed-off-by: Wiktor Mis <mwiktor023@gmail.com>
> ---
>     Add completion for short options
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2100%2FWiktorro%2Fpatch-3-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2100/Wiktorro/patch-3-v1
> Pull-Request: https://github.com/git/git/pull/2100
>
>  contrib/completion/git-completion.bash | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 73abea31b4..3f1d6c0955 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -3916,6 +3916,16 @@ __git_main ()
>  			--help
>  			"
>  			;;
> +		-*)
> +			__gitcomp "
> +			-C
> +			-P
> +			-c
> +			-h
> +			-p
> +			-v
> +			"
> +			;;
When you type
    $ git -<TAB>

the current completion without this patch does nothing. The above change makes it instead show the listed six.

Which is a good enough incremental update, I guess.
I however wonder if a separate follow-up change to let
    $ git -<TAB>

to show completion for both short and long options make the world even a better place. With the current completion, even with this patch, you need to type double-dash-and-TAB to ask for list of long options.

Thanks, will queue.
Wiktor Mis via GitGitGadget· Nov 26, 2025, 16:26 UTC · re: Wiktor Mis via GitGitGadget · lore

[PATCH v2] completion: complete "git -<TAB>" with short options

From: Wiktor Mis <mwiktor023@gmail.com>
"git" itself has completion for long options and cmds, but not short ones
Signed-off-by: Wiktor Mis <mwiktor023@gmail.com>
---
    Add completion for short options
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2100%2FWiktorro%2Fpatch-3-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2100/Wiktorro/patch-3-v2
Pull-Request: https://github.com/git/git/pull/2100
Range-diff vs v1:
 1:  1b15a0b458 ! 1:  e6161ffe3b Add completion for short options
     @@ Metadata
      Author: Wiktor Mis <mwiktor023@gmail.com>
      
       ## Commit message ##
     -    Add completion for short options
     +    completion: complete "git -<TAB>" with short options
      
     -    Git provided completion for long options but not the short ones
     +    "git" itself has completion for long options and cmds, but not short ones
      
          Signed-off-by: Wiktor Mis <mwiktor023@gmail.com>
      
       ## contrib/completion/git-completion.bash ##
      @@ contrib/completion/git-completion.bash: __git_main ()
     - 			--help
     - 			"
       			;;
     + 		esac
     + 		case "$cur" in
     +-		--*)
      +		-*)
     -+			__gitcomp "
     + 			__gitcomp "
     + 			--paginate
     + 			--no-pager
     +@@ contrib/completion/git-completion.bash: __git_main ()
     + 			--namespace=
     + 			--no-replace-objects
     + 			--help
      +			-C
      +			-P
      +			-c
      +			-h
      +			-p
      +			-v
     -+			"
     -+			;;
     + 			"
     + 			;;
       		*)
     - 			if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
     - 			then
 contrib/completion/git-completion.bash | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Show changes to contrib/completion/git-completion.bash +7 −1
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 73abea31b4..1705ca3323 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -3898,7 +3898,7 @@ __git_main ()
 			;;
 		esac
 		case "$cur" in
-		--*)
+		-*)
 			__gitcomp "
 			--paginate
 			--no-pager
@@ -3914,6 +3914,12 @@ __git_main ()
 			--namespace=
 			--no-replace-objects
 			--help
+			-C
+			-P
+			-c
+			-h
+			-p
+			-v
 			"
 			;;
 		*)

base-commit: fd372d9b1a69a01a676398882bbe3840bf51fe72
-- 
gitgitgadget
Junio C Hamano· Nov 26, 2025, 20:09 UTC · re: Wiktor Mis via GitGitGadget · lore

Re: [PATCH v2] completion: complete "git -<TAB>" with short options

"Wiktor Mis via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 7 quoted lines
> From: Wiktor Mis <mwiktor023@gmail.com>
>
> "git" itself has completion for long options and cmds, but not short ones
>
> Signed-off-by: Wiktor Mis <mwiktor023@gmail.com>
> ---
>     Add completion for short options

Will queue with a slight update to the log message. I am unsure if we want to limit "-<TAB>" to one-letter options or if we want to include the long ones (the latter is what v2 implements), but let's see if others have strong opinions.

    completion: complete "git -<TAB>" with short options
    "git" itself has completion for its long options and subcommands,
    but not for its short options.  Add support for them.
    Signed-off-by: Wiktor Mis <mwiktor023@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thanks.
Show 31 quoted lines
>  contrib/completion/git-completion.bash | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 73abea31b4..1705ca3323 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -3898,7 +3898,7 @@ __git_main ()
>  			;;
>  		esac
>  		case "$cur" in
> -		--*)
> +		-*)
>  			__gitcomp "
>  			--paginate
>  			--no-pager
> @@ -3914,6 +3914,12 @@ __git_main ()
>  			--namespace=
>  			--no-replace-objects
>  			--help
> +			-C
> +			-P
> +			-c
> +			-h
> +			-p
> +			-v
>  			"
>  			;;
>  		*)
>
> base-commit: fd372d9b1a69a01a676398882bbe3840bf51fe72
SZEDER Gábor· Nov 27, 2025, 07:33 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] completion: complete "git -<TAB>" with short options

On Wed, Nov 26, 2025 at 12:09:22PM -0800, Junio C Hamano wrote:
Show 19 quoted lines
> "Wiktor Mis via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
> > From: Wiktor Mis <mwiktor023@gmail.com>
> >
> > "git" itself has completion for long options and cmds, but not short ones
> >
> > Signed-off-by: Wiktor Mis <mwiktor023@gmail.com>
> > ---
> >     Add completion for short options
> 
> Will queue with a slight update to the log message.  I am unsure if
> we want to limit "-<TAB>" to one-letter options or if we want to
> include the long ones (the latter is what v2 implements), but let's
> see if others have strong opinions.
> 
>     completion: complete "git -<TAB>" with short options
> 
>     "git" itself has completion for its long options and subcommands,
>     but not for its short options.  Add support for them.

It's not just git itself that doesn't have completion for its short options, but the completion script in general doesn't complete the short options for anything. The reason being, I think, that it doesn't save keystrokes and it doesn't really help discoverability (Well, okay, strictly speaking it does help discoverability in the sense that 'git -<TAB>' will show the existence of short options, but since short options don't have self-explanatory names, the users won't know what those short options are good for. E.g. I just learned from this patch that the main git command accepts -p and -P options, but I have no idea what they are doing.)

So overall I'm somewhat negative on this patch and in general on the direction it takes us, but if we do want to go in this direction, then it will definitely need more justification than this.

Show 36 quoted lines
>     Signed-off-by: Wiktor Mis <mwiktor023@gmail.com>
>     Signed-off-by: Junio C Hamano <gitster@pobox.com>
> 
> Thanks.
> 
> >  contrib/completion/git-completion.bash | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> > index 73abea31b4..1705ca3323 100644
> > --- a/contrib/completion/git-completion.bash
> > +++ b/contrib/completion/git-completion.bash
> > @@ -3898,7 +3898,7 @@ __git_main ()
> >  			;;
> >  		esac
> >  		case "$cur" in
> > -		--*)
> > +		-*)
> >  			__gitcomp "
> >  			--paginate
> >  			--no-pager
> > @@ -3914,6 +3914,12 @@ __git_main ()
> >  			--namespace=
> >  			--no-replace-objects
> >  			--help
> > +			-C
> > +			-P
> > +			-c
> > +			-h
> > +			-p
> > +			-v
> >  			"
> >  			;;
> >  		*)
> >
> > base-commit: fd372d9b1a69a01a676398882bbe3840bf51fe72
Junio C Hamano· Nov 27, 2025, 21:59 UTC · re: SZEDER Gábor · lore

Re: [PATCH v2] completion: complete "git -<TAB>" with short options

SZEDER Gábor <szeder.dev@gmail.com> writes:
Show 7 quoted lines
> know what those short options are good for.  E.g. I just learned from
> this patch that the main git command accepts -p and -P options, but I
> have no idea what they are doing.)
>
> So overall I'm somewhat negative on this patch and in general on the
> direction it takes us, but if we do want to go in this direction, then
> it will definitely need more justification than this.
Ah, yes, I totally forgot earlier discussions we had long ago, e.g.,
  https://lore.kernel.org/git/20070205024704.GB12917@spearce.org/

Completing potential values for a single letter short option is one thihng, but completing single letter short options themselves, unless the completion script can offer a short-help somehow, e.g.,

    $ git -<TAB><TAB>
    -C (chdir there before running the command)
    -p (enable pager)
    ...
I agree that it would not be of much use.
Junio C Hamano· Dec 7, 2025, 00:38 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] completion: complete "git -<TAB>" with short options

Junio C Hamano <gitster@pobox.com> writes:
Show 24 quoted lines
> SZEDER Gábor <szeder.dev@gmail.com> writes:
>
>> know what those short options are good for.  E.g. I just learned from
>> this patch that the main git command accepts -p and -P options, but I
>> have no idea what they are doing.)
>>
>> So overall I'm somewhat negative on this patch and in general on the
>> direction it takes us, but if we do want to go in this direction, then
>> it will definitely need more justification than this.
>
> Ah, yes, I totally forgot earlier discussions we had long ago, e.g.,
>
>   https://lore.kernel.org/git/20070205024704.GB12917@spearce.org/
>
> Completing potential values for a single letter short option is one
> thihng, but completing single letter short options themselves,
> unless the completion script can offer a short-help somehow, e.g.,
>
>     $ git -<TAB><TAB>
>     -C (chdir there before running the command)
>     -p (enable pager)
>     ...
>
> I agree that it would not be of much use.

We did not see any more comments on this thread during my vacation ;-) so let me declare that we will discard this topic.

Thanks everybody for particupating, and thanks Wiktor for attempting to make Git a better system.

← back to recent threads