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

[PATCH] bash completion: Add completion for 'git grep'

From
Lee Marlow <lee.marlow@gmail.com>
Date
Aug 4, 2008, 05:26 UTC
Message-ID
<1217827608-5143-1-git-send-email-lee.marlow@gmail.com>
In-Reply-To
<20080804040634.GC2963@spearce.org>
Added completions for all long options specified in the docs
	--cached
	--text --ignore-case --word-regexp --invert-match
	--full-name
	--extended-regexp --basic-regexp --fixed-strings
	--files-with-matches --name-only
	--files-without-match
	--count
	--and --or --not --all-match
Signed-off-by: Lee Marlow <lee.marlow@gmail.com>
---
On Sun, Aug 3, 2008 at 10:06 PM, Shawn O. Pearce <spearce@spearce.org> wrote:
Show 5 quoted lines
> Though I think you have an excellent point about completing paths
> by ls-tree for HEAD rather than the working directory itself,
> as then you can avoid produced files.  But in practice how often
> do you pass a single file or a couple of files to the grep utility
> and are having problems bypassing the build products?

I think you're right that it's not a good fit for grep, but maybe for some other commands. mv and commit come to mind. I'll look into this as I'm trying to add completions for the more common (i.e. ones that I use) porcelain commands.

> After having thought about it your original patch makes the most
> sense, but without the has_doubledash test.

This updated patch removes the __git_has_doublehash line. However, I just noticed that d773c631 added __git_has_doublehash to prevent completions of long options after --. So, maybe it's not too redundant and my first patch might be better.

-Lee
 contrib/completion/git-completion.bash |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 678a155..96181dc 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -791,6 +791,27 @@ _git_gc ()
 	COMPREPLY=()
 }
 
+_git_grep ()
+{
+	local cur="${COMP_WORDS[COMP_CWORD]}"
+	case "$cur" in
+	--*)
+		__gitcomp "
+			--cached
+			--text --ignore-case --word-regexp --invert-match
+			--full-name
+			--extended-regexp --basic-regexp --fixed-strings
+			--files-with-matches --name-only
+			--files-without-match
+			--count
+			--and --or --not --all-match
+			"
+		return
+		;;
+	esac
+	COMPREPLY=()
+}
+
 _git_help ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -1482,6 +1503,7 @@ _git ()
 	fetch)       _git_fetch ;;
 	format-patch) _git_format_patch ;;
 	gc)          _git_gc ;;
+	grep)        _git_grep ;;
 	help)        _git_help ;;
 	log)         _git_log ;;
 	ls-remote)   _git_ls_remote ;;
-- 
1.6.0.rc1.48.g2b6032
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 5 of 7 in “bash completion: Add completion for 'git grep'”
  1. bash completion: Add completion for 'git grep'Lee Marlow, Aug 2, 2008
  2. Shawn O. PearceAug 2, 2008
  3. Lee MarlowAug 3, 2008
  4. Shawn O. PearceAug 4, 2008
  5. bash completion: Add completion for 'git grep'Lee Marlow, Aug 4, 2008
  6. Shawn O. PearceAug 4, 2008
  7. Shawn O. PearceAug 4, 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.