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

[PATCH] completion: Replace config --list with --get-regexp

From
Todd Zullinger <tmz@pobox.com>
Date
Sep 11, 2009, 23:23 UTC
Message-ID
<20090911232344.GH2582@inocybe.localdomain>
In-Reply-To
<20090911150934.GB977@coredump.intra.peff.net>

James Bardin noted that the completion spewed warnings when no git config file is present. This is likely a bug to be fixed in git config, but it's also a good excuse to simplify the completion code by using the --get-regexp option as Jeff King pointed out.

Signed-off-by: Todd Zullinger <tmz@pobox.com>
---
Jeff King wrote:
Show 11 quoted lines
> On Fri, Sep 11, 2009 at 07:36:51AM -0700, Shawn O. Pearce wrote:
>
>>> instead of just using "git config --get-regexp 'remote\..*\.url'", which
>>> would be slightly more efficient, and also doesn't have this bug. ;)
>>
>> F'king oversight.  You are right, this should be --get-regexp.
>> There isn't a reason here, probably other than "I forgot about
>> --get-regexp when I wrote the original code".
>
> OK. I will leave a bash-completion patch for you (or somebody else
> interested) as I don't use it myself.

Something like this perhaps? Perhaps the commit message could use adjustment to reference your fix for 'config --list'?

 contrib/completion/git-completion.bash |   30 +++++++++---------------------
 1 files changed, 9 insertions(+), 21 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index bf688e1..d668fc9 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -318,13 +318,9 @@ __git_remotes ()
 		echo ${i#$d/remotes/}
 	done
 	[ "$ngoff" ] && shopt -u nullglob
-	for i in $(git --git-dir="$d" config --list); do
-		case "$i" in
-		remote.*.url=*)
-			i="${i#remote.}"
-			echo "${i/.url=*/}"
-			;;
-		esac
+	for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
+		i="${i#remote.}"
+		echo "${i/.url*/}"
 	done
 }
 
@@ -605,13 +601,9 @@ __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
 __git_aliases ()
 {
 	local i IFS=$'\n'
-	for i in $(git --git-dir="$(__gitdir)" config --list); do
-		case "$i" in
-		alias.*)
-			i="${i#alias.}"
-			echo "${i/=*/}"
-			;;
-		esac
+	for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
+		i="${i#alias.}"
+		echo "${i/ */}"
 	done
 }
 
@@ -1769,13 +1761,9 @@ _git_remote ()
 		;;
 	update)
 		local i c='' IFS=$'\n'
-		for i in $(git --git-dir="$(__gitdir)" config --list); do
-			case "$i" in
-			remotes.*)
-				i="${i#remotes.}"
-				c="$c ${i/=*/}"
-				;;
-			esac
+		for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
+			i="${i#remotes.}"
+			c="$c ${i/ */}"
 		done
 		__gitcomp "$c"
 		;;
-- 
1.6.4.2

-- 
Todd        OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
That men do not learn very much from the lessons of history is the
most important of all the lessons of history.
    -- Aldous Huxley Collected Essays, 1959
Previous: Jeff KingNext: Shawn O. Pearce
Message 16 of 20 in “bash_completion outside repo”
  1. james bardinSep 10, 2009
  2. Michael J GruberSep 11, 2009
  3. Todd ZullingerSep 11, 2009
  4. james bardinSep 11, 2009
  5. Jeff KingSep 11, 2009
  6. Shawn O. PearceSep 11, 2009
  7. Jeff KingSep 11, 2009
  8. Jeff KingSep 11, 2009
  9. Junio C HamanoSep 11, 2009
  10. Jeff KingSep 11, 2009
  11. Junio C HamanoSep 11, 2009
  12. Jeff KingSep 11, 2009
  13. Junio C HamanoSep 11, 2009
  14. Junio C HamanoSep 11, 2009
  15. Jeff KingSep 11, 2009
  16. completion: Replace config --list with --get-regexpTodd Zullinger, Sep 11, 2009
  17. Shawn O. PearceSep 12, 2009
  18. Bert WesargSep 13, 2009
  19. Todd ZullingerSep 13, 2009
  20. Junio C HamanoSep 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.