Skip to contentSkip to conversation

Add completion for short options

PATCH In review Wiktor Mis via GitGitGadget 3 participants 7 messages Nov 25, 2025 – Dec 7, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add completion for short options

From: Wiktor Mis <[email protected]>

Git provided completion for long options but not the short ones

---
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(+)
contrib/completion/git-completion.bash +10 -0
index 73abea31b4..3f1d6c0955 100644
@@ -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

Signature · 1 line
gitgitgadget
#1 lore raw

"Wiktor Mis via GitGitGadget" <[email protected]> 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.

Quoted 1 line

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.

Quoted 3 lines

From: Wiktor Mis <[email protected]>

Git provided completion for long options but not the short ones

Complete the sentence with something like

... not the short ones for "git" itself.

Quoted 19 lines

---
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(+)
contrib/completion/git-completion.bash +0 -0
index 73abea31b4..3f1d6c0955 100644
@@ -3916,6 +3916,16 @@ __git_main ()
 			--help
 			"
 			;;

contrib/completion/git-completion.bash __git_main () · line 3928

Quoted 10 lines
contrib/completion/git-completion.bash +10 -0
+		-*)
+			__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.

#2 lore raw

PATCH v2 1/1 completion: complete "git -<TAB>" with short options

In reply to Wiktor Mis via GitGitGadget

From: Wiktor Mis <[email protected]>

"git" itself has completion for long options and cmds, but not short ones

---
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 <[email protected]>

## 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

## 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(-)
contrib/completion/git-completion.bash +7 -1
index 73abea31b4..1705ca3323 100644
@@ -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

Signature · 1 line
gitgitgadget
#3 lore raw

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

Quoted 7 lines · Wiktor Mis via GitGitGadget

From: Wiktor Mis <[email protected]>

"git" itself has completion for long options and cmds, but not short ones

---
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.

Thanks.

Quoted 31 lines
 contrib/completion/git-completion.bash | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
contrib/completion/git-completion.bash +7 -1
index 73abea31b4..1705ca3323 100644
@@ -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

#4 lore raw

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

Quoted 15 lines · Junio C Hamano
Quoted 7 lines · Wiktor Mis via GitGitGadget

From: Wiktor Mis <[email protected]>

"git" itself has completion for long options and cmds, but not short ones

---
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.

Quoted 4 lines

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.

Quoted 36 lines

Thanks.

Quoted 31 lines
 contrib/completion/git-completion.bash | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
contrib/completion/git-completion.bash +7 -1
index 73abea31b4..1705ca3323 100644
@@ -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

#5 lore raw

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

Quoted 7 lines · SZEDER Gábor

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/[email protected]/

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.

#6 lore raw

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

Quoted 18 lines · Junio C Hamano
Quoted 7 lines · SZEDER Gábor

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/[email protected]/

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.,

Quoted 6 lines
    $ 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.