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

[PATCH] bash completion only provides revs, not paths

From
Shawn O. Pearce <spearce@spearce.org>
Date
Apr 24, 2008, 01:21 UTC
Message-ID
<20080424012129.GU29771@spearce.org>
In-Reply-To
<20080423055637.GA25446@digi.com>
Uwe Kleine-Knig <Uwe.Kleine-Koenig@digi.com> wrote:
> > How is this?
>
> I like it and have already applied it.
...
> > Suggested-by: Uwe Kleine-Knig <Uwe.Kleine-Koenig@digi.com>
>
> There is a letter missing in my name.  I wonder why it's always the only
> non-ascii one :-)
Damn.  I'm sorry.  My mailer seems to be dropping it when I
quote you, and I copied your name from the "... wrote:" line
at the top of my message.  I should have copied from the
To: header, where it hasn't been munged.
Fixed commit message below.

--8<-- bash completion: Completely only path names after -- in options

If the user has inserted a -- before the current argument we are being asked to complete they are most likely trying to force Git into treating this argument as a path name, and not as a ref. We should allow bash to complete it as a path from the local working directory.

Tested-by: Uwe Kleine-König <Uwe.Kleine-Koenig@digi.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 contrib/completion/git-completion.bash |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 0f5d30c..8d8405e 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -308,7 +308,20 @@ __git_complete_file ()
 
 __git_complete_revlist ()
 {
-	local pfx cur="${COMP_WORDS[COMP_CWORD]}"
+	local c=1 pfx cur
+
+	while [ $c -lt $COMP_CWORD ]; do
+		cur="${COMP_WORDS[c]}"
+		case "$cur" in
+		--)
+			COMPREPLY=()
+			return
+			;;
+		esac
+		c=$((++c))
+	done
+
+	cur="${COMP_WORDS[COMP_CWORD]}"
 	case "$cur" in
 	*...*)
 		pfx="${cur%...*}..."
-- 
1.5.5.1.141.gd55b


-- 
Shawn.
Previous: Uwe Kleine-KönigNext: Uwe Kleine-König
Message 4 of 5 in “bash completion only provides revs, not paths”
  1. Uwe Kleine-KönigApr 22, 2008
  2. Shawn O. PearceApr 23, 2008
  3. Uwe Kleine-KönigApr 23, 2008
  4. bash completion only provides revs, not pathsShawn O. Pearce, Apr 24, 2008
  5. Uwe Kleine-KönigApr 24, 2008

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.