Thread (6 messages) flat view 6 messages, 3 authors, 2016-06-15
STALE3733d

[PATCH] bash completion: complete refs for git-grep

From: Thomas Rast <hidden>
Date: 2016-06-15 22:47:30
Subsystem: the rest · Maintainer: Linus Torvalds

Before the --, always attempt ref completion.  This helps with
entering the <treeish> arguments to git-grep.  As a bonus, you can
work around git-grep's current lack of --all by hitting M-*, ugly as
the resulting command line may be.

Strictly speaking, completing the regular expression argument (or
option argument) makes no sense.  However, we cannot prevent _all_
completion (it will fall back to filenames), so we dispense with any
additional complication to detect whether the user still has to enter
a regular expression.

Signed-off-by: Thomas Rast <redacted>
---

Sorry for taking so long; I was swamped all weekend by, well, the
weekend. ;-)

I wrote:
Shawn O. Pearce wrote:
quoted
quoted
This is still RFC because, as you can see in the code below, I tried
to avoid completing at all while the user still needs to supply a
regex.  Sadly, bash turns the COMPREPLY=() into filename completion
anyway.  Is there a way to prevent this?
Not that I know of.  You can turn off default filename completion
when you register the completion function, but that then breaks
like every other git command for completion support because a lot
of them do want to complete filenames.
So I'll roll a simpler patch that just always (before --) completes
refs instead, if that's ok.
So that's what this patch does.


 contrib/completion/git-completion.bash |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6fd7e1d..b08cd77 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1048,7 +1048,8 @@ _git_grep ()
 		return
 		;;
 	esac
-	COMPREPLY=()
+
+	__gitcomp "$(__git_refs)"
 }
 
 _git_help ()
-- 
1.6.5.61.g35405
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help