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

[PATCHv2 1/2] completion: add __git_config_get_set_variables() to get config variables

From
Stephen Boyd <bebarino@gmail.com>
Date
May 9, 2009, 01:23 UTC
Message-ID
<1241832213-23070-2-git-send-email-bebarino@gmail.com>
In-Reply-To
<1241832213-23070-1-git-send-email-bebarino@gmail.com>

This function retrieves the set configuration variables from the appropriate configuration file. For example, if the user has previously specified --global only the global variables are returned. The same applies for --system, and --file. If no location has been specified, all set variables are returned.

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
 contrib/completion/git-completion.bash |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 1683e6d..e73359c 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1322,6 +1322,35 @@ _git_send_email ()
 	COMPREPLY=()
 }
 
+__git_config_get_set_variables ()
+{
+	local prevword word config_file= c=$COMP_CWORD
+	while [ $c -gt 1 ]; do
+		word="${COMP_WORDS[c]}"
+		case "$word" in
+		--global|--system|--file=*)
+			config_file="$word"
+			break
+			;;
+		-f|--file)
+			config_file="$word $prevword"
+			break
+			;;
+		esac
+		prevword=$word
+		c=$((--c))
+	done
+
+	for i in $(git --git-dir="$(__gitdir)" config $config_file --list \
+			2>/dev/null); do
+		case "$i" in
+		*.*)
+			echo "${i/=*/}"
+			;;
+		esac
+	done
+}
+
 _git_config ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}"
-- 
1.6.3
Previous: Stephen BoydNext: Stephen Boyd
Message 2 of 9 in “[PATCHv2 0/2] completion: config --unset/get”
  1. Stephen BoydMay 9, 2009
  2. 1/2 completion: add __git_config_get_set_variables() to get config variablesStephen Boyd, May 9, 2009
  3. 2/2 completion: complete config variables for --get/getall/unset/unset-allStephen Boyd, May 9, 2009
  4. Shawn O. PearceMay 9, 2009
  5. Stephen BoydMay 12, 2009
  6. Junio C HamanoMay 12, 2009
  7. Stephen BoydMay 12, 2009
  8. Junio C HamanoMay 13, 2009
  9. Stephen BoydMay 13, 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.