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

[PATCH 2/3] completion: add find_argument_and_value() function

From
Stephen Boyd <bebarino@gmail.com>
Date
May 7, 2009, 06:15 UTC
Message-ID
<1241676906-29783-2-git-send-email-bebarino@gmail.com>
In-Reply-To
<1241676906-29783-1-git-send-email-bebarino@gmail.com>

Add a function to get arguments and their associated value. This is used by the config completion to find config file arguments.

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---

I'm not sure if this is correct. It works for the case I have, but others I'm not so sure. Let's just say I'm no bash expert.

 contrib/completion/git-completion.bash |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 72a16a1..f179cc8 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -618,6 +618,31 @@ __git_find_subcommand ()
 	done
 }
 
+# __git_find_argument_and_value requires 1 argument
+__git_find_argument_and_value ()
+{
+	local word nextword argument c=1
+
+	while [ $c -lt $COMP_CWORD ]; do
+		word="${COMP_WORDS[c]}"
+		for argument in $1; do
+			if [ "${argument##--}" = "${word##--}" ]; then
+				nextword=${COMP_WORDS[$((c+1))]}
+				if [ "${nextword#-}" != "$nextword" ]; then
+					nextword=
+				fi
+				echo "$argument $nextword"
+				return
+			fi
+			if [ "${argument/=*/}" = "${word/=*/}" ]; then
+				echo "$word"
+				return
+			fi
+		done
+		c=$((++c))
+	done
+}
+
 __git_has_doubledash ()
 {
 	local c=1
-- 
1.6.3.rc4.29.g8146
Previous: Stephen BoydNext: Stephen Boyd
Message 2 of 7 in “completion: complete config variables for --get/getall/unset/unset-all”
  1. 1/3 completion: complete config variables for --get/getall/unset/unset-allStephen Boyd, May 7, 2009
  2. 2/3 completion: add find_argument_and_value() functionStephen Boyd, May 7, 2009
  3. 2/3 completion: add find_argument_and_value() functionStephen Boyd, May 7, 2009
  4. 3/3 completion: use specified file (if any) when completing config varsStephen Boyd, May 7, 2009
  5. Shawn O. PearceMay 7, 2009
  6. Stephen BoydMay 7, 2009
  7. Stephen BoydMay 9, 2009

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.