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

[PATCH 3/6] Bash completion support for remotes in .git/config.

From
Shawn O. Pearce <spearce@spearce.org>
Date
Nov 5, 2006, 11:21 UTC
Message-ID
<20061105112103.GC20495@spearce.org>

Now that Git natively supports remote specifications within the config file such as:

	[remote "origin"]
		url = ...

we should provide bash completion support "out of the box" for these remotes, just like we do for the .git/remotes directory.

Also cleaned up the __git_aliases expansion to use the same form of querying and filtering repo-config as this saves two fork/execs in the middle of a user prompted completion. Finally also forced the variable 'word' to be local within __git_aliased_command.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 926638d..5f1be46 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -59,12 +59,21 @@ __git_refs2 ()
 
 __git_remotes ()
 {
-	local i REVERTGLOB=$(shopt -p nullglob)
+	local i ngoff IFS=$'\n'
+	shopt -q nullglob || ngoff=1
 	shopt -s nullglob
 	for i in .git/remotes/*; do
 		echo ${i#.git/remotes/}
 	done
-	$REVERTGLOB
+	[ "$ngoff" ] && shopt -u nullglob
+	for i in $(git repo-config --list); do
+		case "$i" in
+		remote.*.url=*)
+			i="${i#remote.}"
+			echo "${i/.url=*/}"
+			;;
+		esac
+	done
 }
 
 __git_complete_file ()
@@ -103,13 +112,20 @@ __git_complete_file ()
 
 __git_aliases ()
 {
-	git repo-config --list | grep '^alias\.' \
-		| sed -e 's/^alias\.//' -e 's/=.*$//'
+	local i IFS=$'\n'
+	for i in $(git repo-config --list); do
+		case "$i" in
+		alias.*)
+			i="${i#alias.}"
+			echo "${i/=*/}"
+			;;
+		esac
+	done
 }
 
 __git_aliased_command ()
 {
-	local cmdline=$(git repo-config alias.$1)
+	local word cmdline=$(git repo-config --get "alias.$1")
 	for word in $cmdline; do
 		if [ "${word##-*}" ]; then
 			echo $word
-- 
1.4.3.3.g9621
Message 1 of 1 in “Bash completion support for remotes in .git/config.”
  1. 3/6 Bash completion support for remotes in .git/config.Shawn O. Pearce, Nov 5, 2006

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.