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

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

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

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.

Signed-off-by: Cornelius Weig <cornelius.weig@tngtech.com>
Reviewed-by: SZEDER Gábor <szeder.dev@gmail.com>
---
 contrib/completion/git-completion.bash | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6721ff8..c54a557 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -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 ()
-- 
2.10.2
Previous: cornelius.weig@tngtech.comNext: cornelius.weig@tngtech.com
Message 7 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.