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

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

From
Ccornelius.weig@tngtech.com <cornelius.weig@tngtech.com>
Date
Feb 3, 2017, 11:01 UTC
Message-ID
<20170203110159.377-7-cornelius.weig@tngtech.com>
In-Reply-To
<20170203110159.377-1-cornelius.weig@tngtech.com>
From: Cornelius Weig <cornelius.weig@tngtech.com>

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
Signed-off-by: Cornelius Weig <cornelius.weig@tngtech.com>
Reviewed-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 contrib/completion/git-completion.bash | 45 ++++++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 7 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 4841036..d8960cf 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -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
 }
-- 
2.10.2
Previous: cornelius.weig@tngtech.comNext: cornelius.weig@tngtech.com
Message 6 of 10 in “completion bash: add more options and commands”
  1. 0/7 completion bash: add more options and commandscornelius.weig@tngtech.com, Feb 3, 2017
  2. 3/7 completion: improve bash completion for git-addcornelius.weig@tngtech.com, Feb 3, 2017
  3. 4/7 completion: teach ls-remote to complete optionscornelius.weig@tngtech.com, Feb 3, 2017
  4. 7/7 completion: recognize more long-optionscornelius.weig@tngtech.com, Feb 3, 2017
  5. 5/7 completion: teach replace to complete optionscornelius.weig@tngtech.com, Feb 3, 2017
  6. 6/7 completion: teach remote subcommands to complete optionscornelius.weig@tngtech.com, Feb 3, 2017
  7. 1/7 completion: teach submodule subcommands to complete optionscornelius.weig@tngtech.com, Feb 3, 2017
  8. 2/7 completion: add subcommand completion for rererecornelius.weig@tngtech.com, Feb 3, 2017
  9. Junio C HamanoFeb 6, 2017
  10. Johannes SixtFeb 7, 2017

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.