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

[PATCH] bash: support more 'git notes' subcommands and their options

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Oct 10, 2010, 21:43 UTC
Message-ID
<1286747013-8325-1-git-send-email-szeder@ira.uka.de>

The current completion function for 'git notes' only supported the 'edit' and 'show' subcommands and none of their options. This patch adds support for all missing subcommands, options, and their arguments (files or refs), if any.

The code responsible for completing subcommand looks different compared to the completion functions of other git commands with subcommands. This is because of the '--ref <notes-ref>' option which comes before the subcommand (i.e. git notes --ref <notes-ref> add).

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |   50 ++++++++++++++++++++++++++------
 1 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6756990..d57316c 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1468,18 +1468,50 @@ _git_name_rev ()
 
 _git_notes ()
 {
-	local subcommands="edit show"
-	if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
-		__gitcomp "$subcommands"
-		return
-	fi
+	local subcommands='add append copy edit list prune remove show'
+	local subcommand="$(__git_find_on_cmdline "$subcommands")"
+	local cur="${COMP_WORDS[COMP_CWORD]}"
 
-	case "${COMP_WORDS[COMP_CWORD-1]}" in
-	-m|-F)
-		COMPREPLY=()
+	case "$subcommand,$cur" in
+	,--*)
+		__gitcomp '--ref'
+		;;
+	,*)
+		case "${COMP_WORDS[COMP_CWORD-1]}" in
+		--ref)
+			__gitcomp "$(__git_refs)"
+			;;
+		*)
+			__gitcomp "$subcommands --ref"
+			;;
+		esac
+		;;
+	add,--reuse-message=*|append,--reuse-message=*)
+		__gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
+		;;
+	add,--reedit-message=*|append,--reedit-message=*)
+		__gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
+		;;
+	add,--*|append,--*)
+		__gitcomp '--file= --message= --reedit-message=
+				--reuse-message='
+		;;
+	copy,--*)
+		__gitcomp '--stdin'
+		;;
+	prune,--*)
+		__gitcomp '--dry-run --verbose'
+		;;
+	prune,*)
 		;;
 	*)
-		__gitcomp "$(__git_refs)"
+		case "${COMP_WORDS[COMP_CWORD-1]}" in
+		-m|-F)
+			;;
+		*)
+			__gitcomp "$(__git_refs)"
+			;;
+		esac
 		;;
 	esac
 }
-- 
1.7.3.1.148.g2fffa
Message 1 of 1 in “bash: support more 'git notes' subcommands and their options”
  1. bash: support more 'git notes' subcommands and their optionsSZEDER Gábor, Oct 10, 2010

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.