* [PATCH] bash completion: Add completion for 'git grep'
@ 2008-08-02 0:56 Lee Marlow
2008-08-02 21:05 ` Shawn O. Pearce
2008-08-04 14:53 ` Shawn O. Pearce
0 siblings, 2 replies; 7+ messages in thread
From: Lee Marlow @ 2008-08-02 0:56 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git, Lee Marlow
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>
---
contrib/completion/git-completion.bash | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 30d8701..b28ac10 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -796,6 +796,29 @@ _git_gc ()
COMPREPLY=()
}
+_git_grep ()
+{
+ __git_has_doubledash && return
+
+ 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]}"
@@ -1486,6 +1509,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.27.g9b6bf
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] bash completion: Add completion for 'git grep'
2008-08-02 0:56 [PATCH] bash completion: Add completion for 'git grep' Lee Marlow
@ 2008-08-02 21:05 ` Shawn O. Pearce
2008-08-03 7:31 ` Lee Marlow
2008-08-04 14:53 ` Shawn O. Pearce
1 sibling, 1 reply; 7+ messages in thread
From: Shawn O. Pearce @ 2008-08-02 21:05 UTC (permalink / raw)
To: Lee Marlow; +Cc: git
Lee Marlow <lee.marlow@gmail.com> wrote:
> +_git_grep ()
> +{
> + __git_has_doubledash && return
> +
> + 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=()
> +}
Hmm. The has_doubledash test seems redundant since we don't do
anything with args that aren't --foo. Even though git-grep will
accept a tree-ish and thus completion of __git_refs here may
make sense.
I wonder if we shouldn't just add to the end something like:
__gitcomp "$(__git_refs)"
like the _git_reset function does. Then we can complete a tree-ish
for searching, as well as honor -- to stop tree-ish completion and
go back to file/directory completion.
But that is very much a user question. Do users mostly search a
file in the current working directory, or do they mostly search
a tree-ish?
--
Shawn.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] bash completion: Add completion for 'git grep'
2008-08-02 21:05 ` Shawn O. Pearce
@ 2008-08-03 7:31 ` Lee Marlow
2008-08-04 4:06 ` Shawn O. Pearce
0 siblings, 1 reply; 7+ messages in thread
From: Lee Marlow @ 2008-08-03 7:31 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git
On Sat, Aug 2, 2008 at 3:05 PM, Shawn O. Pearce <spearce@spearce.org> wrote:
>
> Hmm. The has_doubledash test seems redundant since we don't do
> anything with args that aren't --foo. Even though git-grep will
> accept a tree-ish and thus completion of __git_refs here may
> make sense.
>
> But that is very much a user question. Do users mostly search a
> file in the current working directory, or do they mostly search
> a tree-ish?
I haven't found myself using grep to search anything but the current
working directory. I wonder whether __git_complete_file would be
better than __git_refs. My issue with __git_complete_file in this
case and also doing completion for 'git mv' is that it falls back to
just __git_refs. Would it be better if it fell back to __git_refs and
ls-tree for HEAD? That way when using completion to get to
Documentation/git-grep.txt, it doesn't also show completions for
Documentation/git-grep.{1,html,xml}.
-Lee
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] bash completion: Add completion for 'git grep'
2008-08-03 7:31 ` Lee Marlow
@ 2008-08-04 4:06 ` Shawn O. Pearce
2008-08-04 5:26 ` Lee Marlow
0 siblings, 1 reply; 7+ messages in thread
From: Shawn O. Pearce @ 2008-08-04 4:06 UTC (permalink / raw)
To: Lee Marlow; +Cc: git
Lee Marlow <lee.marlow@gmail.com> wrote:
> On Sat, Aug 2, 2008 at 3:05 PM, Shawn O. Pearce <spearce@spearce.org> wrote:
> >
> > Hmm. The has_doubledash test seems redundant since we don't do
> > anything with args that aren't --foo. Even though git-grep will
> > accept a tree-ish and thus completion of __git_refs here may
>
> I haven't found myself using grep to search anything but the current
> working directory. I wonder whether __git_complete_file would be
> better than __git_refs. My issue with __git_complete_file in this
> case and also doing completion for 'git mv' is that it falls back to
> just __git_refs. Would it be better if it fell back to __git_refs and
> ls-tree for HEAD? That way when using completion to get to
> Documentation/git-grep.txt, it doesn't also show completions for
> Documentation/git-grep.{1,html,xml}.
Hmm. __git_complete_file is about completing something in a tree-ish,
which is really most likely not what we want for grep. Its useful for
git-show and git-cat-file, and that's about it. Most git tools prefer
a calling format of "tree-ish -- paths ..." and not "tree-ish:path".
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? Compared to
just running grep on the entire source tree to find hits? I never
use grep to search in a single file, but I call it several times
a day to look for where a function is defined or called.
After having thought about it your original patch makes the most
sense, but without the has_doubledash test.
--
Shawn.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] bash completion: Add completion for 'git grep'
2008-08-04 4:06 ` Shawn O. Pearce
@ 2008-08-04 5:26 ` Lee Marlow
2008-08-04 14:52 ` Shawn O. Pearce
0 siblings, 1 reply; 7+ messages in thread
From: Lee Marlow @ 2008-08-04 5:26 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git, Lee Marlow
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:
> 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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] bash completion: Add completion for 'git grep'
2008-08-04 5:26 ` Lee Marlow
@ 2008-08-04 14:52 ` Shawn O. Pearce
0 siblings, 0 replies; 7+ messages in thread
From: Shawn O. Pearce @ 2008-08-04 14:52 UTC (permalink / raw)
To: Lee Marlow; +Cc: git
Lee Marlow <lee.marlow@gmail.com> wrote:
> 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.
Heh. I forgot about that. You're right, your first patch is better.
--
Shawn.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] bash completion: Add completion for 'git grep'
2008-08-02 0:56 [PATCH] bash completion: Add completion for 'git grep' Lee Marlow
2008-08-02 21:05 ` Shawn O. Pearce
@ 2008-08-04 14:53 ` Shawn O. Pearce
1 sibling, 0 replies; 7+ messages in thread
From: Shawn O. Pearce @ 2008-08-04 14:53 UTC (permalink / raw)
To: Lee Marlow; +Cc: git
Lee Marlow <lee.marlow@gmail.com> wrote:
> 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>
Acked-by: Shawn O. Pearce <spearce@spearce.org>
This is the "first patch" which has the doubledash test. As you
pointed out, its better because it stops completion of long options
after the --.
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 30d8701..b28ac10 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -796,6 +796,29 @@ _git_gc ()
> COMPREPLY=()
> }
>
> +_git_grep ()
> +{
> + __git_has_doubledash && return
> +
> + 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]}"
> @@ -1486,6 +1509,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 ;;
> --
--
Shawn.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-08-04 14:54 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-02 0:56 [PATCH] bash completion: Add completion for 'git grep' Lee Marlow
2008-08-02 21:05 ` Shawn O. Pearce
2008-08-03 7:31 ` Lee Marlow
2008-08-04 4:06 ` Shawn O. Pearce
2008-08-04 5:26 ` Lee Marlow
2008-08-04 14:52 ` Shawn O. Pearce
2008-08-04 14:53 ` Shawn O. Pearce
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).