Skip to contentSkip to conversation

completion bash: add more options and commands

PATCH In review [email protected] 3 participants 10 messages Feb 3, 2017 – Feb 7, 2017

lore
Share & tools
lore
#0 lore raw

v2 cover completion bash: add more options and commands

From: Cornelius Weig <[email protected]>

This is the re-roll of patch series <[email protected]>.

This patch series adds all long-options that are mentioned in the synopsis of the man-page for the respective git-command. There are only a few exceptions, as discussed in the above thread. For example, no unsafe options should be completed.
Furthermore, the patches add subommand option completion for git-submodule and git-remote.

Changes wrt first submission:

- improve completion for git-remote set-head & set-branches
- remove completion of unsafe options
- improve commit messages
- added sign-off :)
- rebase to current master

Cornelius Weig (7):
completion: teach submodule subcommands to complete options
completion: add subcommand completion for rerere
completion: improve bash completion for git-add
completion: teach ls-remote to complete options
completion: teach replace to complete options
completion: teach remote subcommands to complete options
completion: recognize more long-options

 contrib/completion/git-completion.bash | 139 ++++++++++++++++++++++++++++-----
 1 file changed, 118 insertions(+), 21 deletions(-)

Interdiff since first iteration:

contrib/completion/git-completion.bash +12 -3
index 87d3d2c..3545f6a 100644
@@ -936,7 +936,7 @@ _git_apply ()
 			--apply --no-add --exclude=
 			--ignore-whitespace --ignore-space-change
 			--whitespace= --inaccurate-eof --verbose
-			--recount --directory= --unsafe-paths
+			--recount --directory=
 			"
 		return
 	esac
@@ -1459,7 +1459,7 @@ _git_ls_remote ()
 {
 	case "$cur" in
 	--*)
-		__gitcomp "--heads --tags --refs --get-url"
+		__gitcomp "--heads --tags --refs --get-url --symref"
 		return
 		;;
 	esac
@@ -2415,9 +2415,18 @@ _git_remote ()
 		;;
 	add,*)
 		;;
+	set-head,--*)
+		__gitcomp "--auto --delete"
+		;;
+	set-branches,--*)
+		__gitcomp "--add"
+		;;
 	set-head,*|set-branches,*)
 		__git_complete_remote_or_refspec
 		;;
+	update,--*)
+		__gitcomp "--prune"
+		;;
 	update,*)
 		__gitcomp "$(__git_get_config_variables "remotes")"
 		;;
@@ -2494,7 +2503,7 @@ _git_rm ()
 {
 	case "$cur" in
 	--*)
-		__gitcomp "--cached --dry-run --ignore-unmatch --quiet --force"
+		__gitcomp "--cached --dry-run --ignore-unmatch --quiet"
 		return
 		;;
 	esac
Signature · 1 line
2.10.2
#1 lore raw

PATCH v2 1/7 completion: teach submodule subcommands to complete options

From: Cornelius Weig <[email protected]>

Each submodule subcommand has specific long-options. Therefore, teach bash completion to support option completion based on the current subcommand. All long-options that are mentioned in the man-page synopsis are added.

---
 contrib/completion/git-completion.bash | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
contrib/completion/git-completion.bash +30 -2
index 6721ff8..c54a557 100644
@@ -2556,10 +2556,11 @@ _git_submodule ()
 	__git_has_doubledash && return
 
 	local subcommands="add status init deinit update summary foreach sync"
-	if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
+	local subcommand="$(__git_find_on_cmdline "$subcommands")"
+	if [ -z "$subcommand" ]; then
 		case "$cur" in
 		--*)
-			__gitcomp "--quiet --cached"
+			__gitcomp "--quiet"
 			;;
 		*)
 			__gitcomp "$subcommands"
@@ -2567,6 +2568,33 @@ _git_submodule ()
 		esac
 		return
 	fi
+
+	case "$subcommand,$cur" in
+	add,--*)
+		__gitcomp "--branch --force --name --reference --depth"
+		;;
+	status,--*)
+		__gitcomp "--cached --recursive"
+		;;
+	deinit,--*)
+		__gitcomp "--force --all"
+		;;
+	update,--*)
+		__gitcomp "
+			--init --remote --no-fetch
+			--recommend-shallow --no-recommend-shallow
+			--force --rebase --merge --reference --depth --recursive --jobs
+		"
+		;;
+	summary,--*)
+		__gitcomp "--cached --files --summary-limit"
+		;;
+	foreach,--*|sync,--*)
+		__gitcomp "--recursive"
+		;;
+	*)
+		;;
+	esac
 }
 
 _git_svn ()
Signature · 1 line
2.10.2
#2 lore raw

PATCH v2 2/7 completion: add subcommand completion for rerere

In reply to [email protected]

From: Cornelius Weig <[email protected]>

Managing recorded resolutions requires command-line usage of git-rerere. Added subcommand completion for rerere and path completion for its subcommand forget.

---
 contrib/completion/git-completion.bash | 11 +++++++++++
 1 file changed, 11 insertions(+)
contrib/completion/git-completion.bash +11 -0
index c54a557..8329f09 100644
@@ -2401,6 +2401,17 @@ _git_replace ()
 	__gitcomp_nl "$(__git_refs)"
 }
 
+_git_rerere ()
+{
+	local subcommands="clear forget diff remaining status gc"
+	local subcommand="$(__git_find_on_cmdline "$subcommands")"
+	if test -z "$subcommand"
+	then
+		__gitcomp "$subcommands"
+		return
+	fi
+}
+
 _git_reset ()
 {
 	__git_has_doubledash && return
Signature · 1 line
2.10.2
#3 lore raw

PATCH v2 3/7 completion: improve bash completion for git-add

In reply to [email protected]

From: Cornelius Weig <[email protected]>

Command completion for git-add did not recognize some long-options. This commits adds completion for all long-options that are mentioned in the man-page synopsis. In addition, if the user specified --update or -u, path completion will only suggest modified tracked files.

---
 contrib/completion/git-completion.bash | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
contrib/completion/git-completion.bash +7 -3
index 8329f09..652c7e2 100644
@@ -947,13 +947,17 @@ _git_add ()
 	--*)
 		__gitcomp "
 			--interactive --refresh --patch --update --dry-run
-			--ignore-errors --intent-to-add
+			--ignore-errors --intent-to-add --force --edit --chmod=
 			"
 		return
 	esac
 
-	# XXX should we check for --update and --all options ?
-	__git_complete_index_file "--others --modified --directory --no-empty-directory"
+	local complete_opt="--others --modified --directory --no-empty-directory"
+	if test -n "$(__git_find_on_cmdline "-u --update")"
+	then
+		complete_opt="--modified"
+	fi
+	__git_complete_index_file "$complete_opt"
 }
 
 _git_archive ()
Signature · 1 line
2.10.2
#4 lore raw

PATCH v2 4/7 completion: teach ls-remote to complete options

In reply to [email protected]

From: Cornelius Weig <[email protected]>

ls-remote needs to complete remote names and its own options. In addition to the existing remote name completions, do also complete the options --heads, --tags, --refs, --get-url, and --symref.

---
 contrib/completion/git-completion.bash | 6 ++++++
 1 file changed, 6 insertions(+)
contrib/completion/git-completion.bash +6 -0
index 652c7e2..a355eeb 100644
@@ -1449,6 +1449,12 @@ _git_ls_files ()
 
 _git_ls_remote ()
 {
+	case "$cur" in
+	--*)
+		__gitcomp "--heads --tags --refs --get-url --symref"
+		return
+		;;
+	esac
 	__gitcomp_nl "$(__git_remotes)"
 }
 
Signature · 1 line
2.10.2
#5 lore raw

PATCH v2 5/7 completion: teach replace to complete options

In reply to [email protected]

From: Cornelius Weig <[email protected]>

Git-replace needs to complete references and its own options. In addition to the existing references completions, do also complete the options --edit --graft --format= --list --delete.

---
 contrib/completion/git-completion.bash | 6 ++++++
 1 file changed, 6 insertions(+)
contrib/completion/git-completion.bash +6 -0
index a355eeb..4841036 100644
@@ -2408,6 +2408,12 @@ _git_remote ()
 
 _git_replace ()
 {
+	case "$cur" in
+	--*)
+		__gitcomp "--edit --graft --format= --list --delete"
+		return
+		;;
+	esac
 	__gitcomp_nl "$(__git_refs)"
 }
 
Signature · 1 line
2.10.2
#6 lore raw

PATCH v2 6/7 completion: teach remote subcommands to complete options

In reply to [email protected]

From: Cornelius Weig <[email protected]>

Git-remote needs to complete remote names, its subcommands, and options thereof. In addition to the existing subcommand and remote name completion, do also complete the options

- add: --track --master --fetch --tags --no-tags --mirror=
- set-url: --push --add --delete
- get-url: --push --all
- prune: --dry-run

---
 contrib/completion/git-completion.bash | 45 ++++++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 7 deletions(-)
contrib/completion/git-completion.bash +38 -7
index 4841036..d8960cf 100644
@@ -2384,24 +2384,55 @@ _git_config ()
 
 _git_remote ()
 {
-	local subcommands="add rename remove set-head set-branches set-url show prune update"
+	local subcommands="
+		add rename remove set-head set-branches
+		get-url set-url show prune update
+		"
 	local subcommand="$(__git_find_on_cmdline "$subcommands")"
 	if [ -z "$subcommand" ]; then
-		__gitcomp "$subcommands"
+		case "$cur" in
+		--*)
+			__gitcomp "--verbose"
+			;;
+		*)
+			__gitcomp "$subcommands"
+			;;
+		esac
 		return
 	fi
 
-	case "$subcommand" in
-	rename|remove|set-url|show|prune)
-		__gitcomp_nl "$(__git_remotes)"
+	case "$subcommand,$cur" in
+	add,--*)
+		__gitcomp "--track --master --fetch --tags --no-tags --mirror="
+		;;
+	add,*)
+		;;
+	set-head,--*)
+		__gitcomp "--auto --delete"
 		;;
-	set-head|set-branches)
+	set-branches,--*)
+		__gitcomp "--add"
+		;;
+	set-head,*|set-branches,*)
 		__git_complete_remote_or_refspec
 		;;
-	update)
+	update,--*)
+		__gitcomp "--prune"
+		;;
+	update,*)
 		__gitcomp "$(__git_get_config_variables "remotes")"
 		;;
+	set-url,--*)
+		__gitcomp "--push --add --delete"
+		;;
+	get-url,--*)
+		__gitcomp "--push --all"
+		;;
+	prune,--*)
+		__gitcomp "--dry-run"
+		;;
 	*)
+		__gitcomp_nl "$(__git_remotes)"
 		;;
 	esac
 }
Signature · 1 line
2.10.2
#7 lore raw

PATCH v2 7/7 completion: recognize more long-options

In reply to [email protected]

From: Cornelius Weig <[email protected]>

Command completion only recognizes a subset of the available options for the various git commands. The set of recognized options needs to balance between having all useful options and to not clutter the terminal.

This commit adds all long-options that are mentioned in the man-page synopsis of the respective git command. Possibly dangerous options are not included in this set, to avoid accidental data loss. The added options are:

- apply: --recount --directory=
- archive: --output
- branch: --column --no-column --sort= --points-at
- clone: --no-single-branch --shallow-submodules
- commit: --patch --short --date --allow-empty
- describe: --first-parent
- fetch, pull: --unshallow --update-shallow
- fsck: --name-objects
- grep: --break --heading --show-function --function-context

         --untracked --no-index

- mergetool: --prompt --no-prompt
- reset: --keep
- revert: --strategy= --strategy-option=
- shortlog: --email
- tag: --merged --no-merged --create-reflog

---
 contrib/completion/git-completion.bash | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
contrib/completion/git-completion.bash +20 -9
index d8960cf..3545f6a 100644
@@ -936,6 +936,7 @@ _git_apply ()
 			--apply --no-add --exclude=
 			--ignore-whitespace --ignore-space-change
 			--whitespace= --inaccurate-eof --verbose
+			--recount --directory=
 			"
 		return
 	esac
@@ -974,7 +975,7 @@ _git_archive ()
 	--*)
 		__gitcomp "
 			--format= --list --verbose
-			--prefix= --remote= --exec=
+			--prefix= --remote= --exec= --output
 			"
 		return
 		;;
@@ -1029,6 +1030,7 @@ _git_branch ()
 			--track --no-track --contains --merged --no-merged
 			--set-upstream-to= --edit-description --list
 			--unset-upstream --delete --move --remotes
+			--column --no-column --sort= --points-at
 			"
 		;;
 	*)
@@ -1142,6 +1144,8 @@ _git_clone ()
 			--single-branch
 			--branch
 			--recurse-submodules
+			--no-single-branch
+			--shallow-submodules
 			"
 		return
 		;;
@@ -1183,6 +1187,7 @@ _git_commit ()
 			--reset-author --file= --message= --template=
 			--cleanup= --untracked-files --untracked-files=
 			--verbose --quiet --fixup= --squash=
+			--patch --short --date --allow-empty
 			"
 		return
 	esac
@@ -1201,7 +1206,7 @@ _git_describe ()
 	--*)
 		__gitcomp "
 			--all --tags --contains --abbrev= --candidates=
-			--exact-match --debug --long --match --always
+			--exact-match --debug --long --match --always --first-parent
 			"
 		return
 	esac
@@ -1284,6 +1289,7 @@ __git_fetch_recurse_submodules="yes on-demand no"
 __git_fetch_options="
 	--quiet --verbose --append --upload-pack --force --keep --depth=
 	--tags --no-tags --all --prune --dry-run --recurse-submodules=
+	--unshallow --update-shallow
 "
 
 _git_fetch ()
@@ -1333,7 +1339,7 @@ _git_fsck ()
 	--*)
 		__gitcomp "
 			--tags --root --unreachable --cache --no-reflogs --full
-			--strict --verbose --lost-found
+			--strict --verbose --lost-found --name-objects
 			"
 		return
 		;;
@@ -1377,6 +1383,8 @@ _git_grep ()
 			--max-depth
 			--count
 			--and --or --not --all-match
+			--break --heading --show-function --function-context
+			--untracked --no-index
 			"
 		return
 		;;
@@ -1576,7 +1584,7 @@ _git_mergetool ()
 		return
 		;;
 	--*)
-		__gitcomp "--tool="
+		__gitcomp "--tool= --prompt --no-prompt"
 		return
 		;;
 	esac
@@ -2465,7 +2473,7 @@ _git_reset ()
 
 	case "$cur" in
 	--*)
-		__gitcomp "--merge --mixed --hard --soft --patch"
+		__gitcomp "--merge --mixed --hard --soft --patch --keep"
 		return
 		;;
 	esac
@@ -2481,7 +2489,10 @@ _git_revert ()
 	fi
 	case "$cur" in
 	--*)
-		__gitcomp "--edit --mainline --no-edit --no-commit --signoff"
+		__gitcomp "
+			--edit --mainline --no-edit --no-commit --signoff
+			--strategy= --strategy-option=
+			"
 		return
 		;;
 	esac
@@ -2509,7 +2520,7 @@ _git_shortlog ()
 		__gitcomp "
 			$__git_log_common_options
 			$__git_log_shortlog_options
-			--numbered --summary
+			--numbered --summary --email
 			"
 		return
 		;;
@@ -2787,8 +2798,8 @@ _git_tag ()
 	--*)
 		__gitcomp "
 			--list --delete --verify --annotate --message --file
-			--sign --cleanup --local-user --force --column --sort
-			--contains --points-at
+			--sign --cleanup --local-user --force --column --sort=
+			--contains --points-at --merged --no-merged --create-reflog
 			"
 		;;
 	esac
Signature · 1 line
2.10.2
#8 lore raw
In reply to [email protected]
Quoted 10 lines · [email protected] writes:

From: Cornelius Weig <[email protected]>

This is the re-roll of patch series <[email protected]>.

This patch series adds all long-options that are mentioned in the synopsis of the man-page for the respective git-command. There are only a few exceptions, as discussed in the above thread. For example, no unsafe options should be completed.
Furthermore, the patches add subommand option completion for git-submodule and git-remote.

Reviewers, do these look good now?

Thanks all.

#9 lore raw

Am 06.02.2017 um 22:29 schrieb Junio C Hamano:

Quoted 6 lines
Quoted 4 lines · [email protected] writes:

From: Cornelius Weig <[email protected]>

This is the re-roll of patch series <[email protected]>.

Quoted 8 lines
Quoted 6 lines

This patch series adds all long-options that are mentioned in the synopsis of the man-page for the respective git-command. There are only a few exceptions, as discussed in the above thread. For example, no unsafe options should be completed.
Furthermore, the patches add subommand option completion for git-submodule and git-remote.

Reviewers, do these look good now?

My concerns have been addressed. The patches look good from a cursory read.

-- Hannes