{"thread":{"id":"14800","subject":"[PATCH] bash completion: Add completion for 'git grep'","startedAt":"2008-08-02T00:56:33Z","lastAt":"2008-08-04T14:53:03Z","messageCount":7,"participants":["Lee Marlow","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"85959","messageId":"1217638593-57321-1-git-send-email-lee.marlow@gmail.com","threadId":"14800","inReplyTo":null,"subject":"[PATCH] bash completion: Add completion for 'git grep'","fromName":"Lee Marlow","fromEmail":"lee.marlow@gmail.com","sentAt":"2008-08-02T00:56:33Z","receivedAt":"2008-08-02T00:56:33Z","isPatch":true,"sender":{"key":"lee.marlow@gmail.com","avatar":"https://gravatar.com/avatar/231170f3c8456cf1af984d30d09f35c5509b5f81494c81fa69dc7a1027473fc0?d=mp&s=160"},"body":"Added completions for all long options specified in the docs\n\t--cached\n\t--text --ignore-case --word-regexp --invert-match\n\t--full-name\n\t--extended-regexp --basic-regexp --fixed-strings\n\t--files-with-matches --name-only\n\t--files-without-match\n\t--count\n\t--and --or --not --all-match\n\nSigned-off-by: Lee Marlow <lee.marlow@gmail.com>\n---\n contrib/completion/git-completion.bash |   24 ++++++++++++++++++++++++\n 1 files changed, 24 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 30d8701..b28ac10 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -796,6 +796,29 @@ _git_gc ()\n \tCOMPREPLY=()\n }\n \n+_git_grep ()\n+{\n+\t__git_has_doubledash && return\n+\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\tcase \"$cur\" in\n+\t--*)\n+\t\t__gitcomp \"\n+\t\t\t--cached\n+\t\t\t--text --ignore-case --word-regexp --invert-match\n+\t\t\t--full-name\n+\t\t\t--extended-regexp --basic-regexp --fixed-strings\n+\t\t\t--files-with-matches --name-only\n+\t\t\t--files-without-match\n+\t\t\t--count\n+\t\t\t--and --or --not --all-match\n+\t\t\t\"\n+\t\treturn\n+\t\t;;\n+\tesac\n+\tCOMPREPLY=()\n+}\n+\n _git_help ()\n {\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n@@ -1486,6 +1509,7 @@ _git ()\n \tfetch)       _git_fetch ;;\n \tformat-patch) _git_format_patch ;;\n \tgc)          _git_gc ;;\n+\tgrep)        _git_grep ;;\n \thelp)        _git_help ;;\n \tlog)         _git_log ;;\n \tls-remote)   _git_ls_remote ;;\n-- \n1.6.0.rc1.27.g9b6bf\n"},{"id":"86013","messageId":"20080802210525.GD24723@spearce.org","threadId":"14800","inReplyTo":"1217638593-57321-1-git-send-email-lee.marlow@gmail.com","subject":"Re: [PATCH] bash completion: Add completion for 'git grep'","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-08-02T21:05:25Z","receivedAt":"2008-08-02T21:05:25Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Lee Marlow <lee.marlow@gmail.com> wrote:\n> +_git_grep ()\n> +{\n> +\t__git_has_doubledash && return\n> +\n> +\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n> +\tcase \"$cur\" in\n> +\t--*)\n> +\t\t__gitcomp \"\n> +\t\t\t--cached\n> +\t\t\t--text --ignore-case --word-regexp --invert-match\n> +\t\t\t--full-name\n> +\t\t\t--extended-regexp --basic-regexp --fixed-strings\n> +\t\t\t--files-with-matches --name-only\n> +\t\t\t--files-without-match\n> +\t\t\t--count\n> +\t\t\t--and --or --not --all-match\n> +\t\t\t\"\n> +\t\treturn\n> +\t\t;;\n> +\tesac\n> +\tCOMPREPLY=()\n> +}\n\n\nHmm.  The has_doubledash test seems redundant since we don't do\nanything with args that aren't --foo.  Even though git-grep will\naccept a tree-ish and thus completion of __git_refs here may\nmake sense.\n\nI wonder if we shouldn't just add to the end something like:\n\n\t__gitcomp \"$(__git_refs)\"\n\nlike the _git_reset function does.  Then we can complete a tree-ish\nfor searching, as well as honor -- to stop tree-ish completion and\ngo back to file/directory completion.\n\nBut that is very much a user question.  Do users mostly search a\nfile in the current working directory, or do they mostly search\na tree-ish?\n\n-- \nShawn.\n"},{"id":"86046","messageId":"7968d7490808030031v39726af6r9f88feb28df02de7@mail.gmail.com","threadId":"14800","inReplyTo":"20080802210525.GD24723@spearce.org","subject":"Re: [PATCH] bash completion: Add completion for 'git grep'","fromName":"Lee Marlow","fromEmail":"lee.marlow@gmail.com","sentAt":"2008-08-03T07:31:13Z","receivedAt":"2008-08-03T07:31:13Z","isPatch":true,"sender":{"key":"lee.marlow@gmail.com","avatar":"https://gravatar.com/avatar/231170f3c8456cf1af984d30d09f35c5509b5f81494c81fa69dc7a1027473fc0?d=mp&s=160"},"body":"On Sat, Aug 2, 2008 at 3:05 PM, Shawn O. Pearce <spearce@spearce.org> wrote:\n>\n> Hmm.  The has_doubledash test seems redundant since we don't do\n> anything with args that aren't --foo.  Even though git-grep will\n> accept a tree-ish and thus completion of __git_refs here may\n> make sense.\n>\n> But that is very much a user question.  Do users mostly search a\n> file in the current working directory, or do they mostly search\n> a tree-ish?\n\nI haven't found myself using grep to search anything but the current\nworking directory.  I wonder whether __git_complete_file would be\nbetter than __git_refs.  My issue with __git_complete_file in this\ncase and also doing completion for 'git mv' is that it falls back to\njust __git_refs.  Would it be better if it fell back to __git_refs and\nls-tree for HEAD?  That way when using completion to get to\nDocumentation/git-grep.txt,  it doesn't also show completions for\nDocumentation/git-grep.{1,html,xml}.\n\n-Lee\n"},{"id":"86146","messageId":"20080804040634.GC2963@spearce.org","threadId":"14800","inReplyTo":"7968d7490808030031v39726af6r9f88feb28df02de7@mail.gmail.com","subject":"Re: [PATCH] bash completion: Add completion for 'git grep'","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-08-04T04:06:34Z","receivedAt":"2008-08-04T04:06:34Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Lee Marlow <lee.marlow@gmail.com> wrote:\n> On Sat, Aug 2, 2008 at 3:05 PM, Shawn O. Pearce <spearce@spearce.org> wrote:\n> >\n> > Hmm.  The has_doubledash test seems redundant since we don't do\n> > anything with args that aren't --foo.  Even though git-grep will\n> > accept a tree-ish and thus completion of __git_refs here may\n> \n> I haven't found myself using grep to search anything but the current\n> working directory.  I wonder whether __git_complete_file would be\n> better than __git_refs.  My issue with __git_complete_file in this\n> case and also doing completion for 'git mv' is that it falls back to\n> just __git_refs.  Would it be better if it fell back to __git_refs and\n> ls-tree for HEAD?  That way when using completion to get to\n> Documentation/git-grep.txt,  it doesn't also show completions for\n> Documentation/git-grep.{1,html,xml}.\n\nHmm.  __git_complete_file is about completing something in a tree-ish,\nwhich is really most likely not what we want for grep.  Its useful for\ngit-show and git-cat-file, and that's about it.  Most git tools prefer\na calling format of \"tree-ish -- paths ...\" and not \"tree-ish:path\".\n\nThough I think you have an excellent point about completing paths\nby ls-tree for HEAD rather than the working directory itself,\nas then you can avoid produced files.  But in practice how often\ndo you pass a single file or a couple of files to the grep utility\nand are having problems bypassing the build products?  Compared to\njust running grep on the entire source tree to find hits?  I never\nuse grep to search in a single file, but I call it several times\na day to look for where a function is defined or called.\n\nAfter having thought about it your original patch makes the most\nsense, but without the has_doubledash test.\n\n-- \nShawn.\n"},{"id":"86150","messageId":"1217827608-5143-1-git-send-email-lee.marlow@gmail.com","threadId":"14800","inReplyTo":"20080804040634.GC2963@spearce.org","subject":"[PATCH] bash completion: Add completion for 'git grep'","fromName":"Lee Marlow","fromEmail":"lee.marlow@gmail.com","sentAt":"2008-08-04T05:26:48Z","receivedAt":"2008-08-04T05:26:48Z","isPatch":true,"sender":{"key":"lee.marlow@gmail.com","avatar":"https://gravatar.com/avatar/231170f3c8456cf1af984d30d09f35c5509b5f81494c81fa69dc7a1027473fc0?d=mp&s=160"},"body":"Added completions for all long options specified in the docs\n\t--cached\n\t--text --ignore-case --word-regexp --invert-match\n\t--full-name\n\t--extended-regexp --basic-regexp --fixed-strings\n\t--files-with-matches --name-only\n\t--files-without-match\n\t--count\n\t--and --or --not --all-match\n\nSigned-off-by: Lee Marlow <lee.marlow@gmail.com>\n---\n\nOn Sun, Aug 3, 2008 at 10:06 PM, Shawn O. Pearce <spearce@spearce.org> wrote:\n> Though I think you have an excellent point about completing paths\n> by ls-tree for HEAD rather than the working directory itself,\n> as then you can avoid produced files.  But in practice how often\n> do you pass a single file or a couple of files to the grep utility\n> and are having problems bypassing the build products?\n\nI think you're right that it's not a good fit for grep, but maybe for\nsome other commands.  mv and commit come to mind.  I'll look into this\nas I'm trying to add completions for the more common (i.e. ones that I\nuse) porcelain commands.\n\n> After having thought about it your original patch makes the most\n> sense, but without the has_doubledash test.\n\nThis updated patch removes the __git_has_doublehash line.  However, I\njust noticed that d773c631 added __git_has_doublehash to prevent\ncompletions of long options after --.  So, maybe it's not too\nredundant and my first patch might be better.\n\n-Lee\n\n contrib/completion/git-completion.bash |   22 ++++++++++++++++++++++\n 1 files changed, 22 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 678a155..96181dc 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -791,6 +791,27 @@ _git_gc ()\n \tCOMPREPLY=()\n }\n \n+_git_grep ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\tcase \"$cur\" in\n+\t--*)\n+\t\t__gitcomp \"\n+\t\t\t--cached\n+\t\t\t--text --ignore-case --word-regexp --invert-match\n+\t\t\t--full-name\n+\t\t\t--extended-regexp --basic-regexp --fixed-strings\n+\t\t\t--files-with-matches --name-only\n+\t\t\t--files-without-match\n+\t\t\t--count\n+\t\t\t--and --or --not --all-match\n+\t\t\t\"\n+\t\treturn\n+\t\t;;\n+\tesac\n+\tCOMPREPLY=()\n+}\n+\n _git_help ()\n {\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n@@ -1482,6 +1503,7 @@ _git ()\n \tfetch)       _git_fetch ;;\n \tformat-patch) _git_format_patch ;;\n \tgc)          _git_gc ;;\n+\tgrep)        _git_grep ;;\n \thelp)        _git_help ;;\n \tlog)         _git_log ;;\n \tls-remote)   _git_ls_remote ;;\n-- \n1.6.0.rc1.48.g2b6032\n"},{"id":"86199","messageId":"20080804145210.GD27666@spearce.org","threadId":"14800","inReplyTo":"1217827608-5143-1-git-send-email-lee.marlow@gmail.com","subject":"Re: [PATCH] bash completion: Add completion for 'git grep'","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-08-04T14:52:10Z","receivedAt":"2008-08-04T14:52:10Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Lee Marlow <lee.marlow@gmail.com> wrote:\n> This updated patch removes the __git_has_doublehash line.  However, I\n> just noticed that d773c631 added __git_has_doublehash to prevent\n> completions of long options after --.  So, maybe it's not too\n> redundant and my first patch might be better.\n\nHeh.  I forgot about that.  You're right, your first patch is better.\n\n-- \nShawn.\n"},{"id":"86200","messageId":"20080804145303.GE27666@spearce.org","threadId":"14800","inReplyTo":"1217638593-57321-1-git-send-email-lee.marlow@gmail.com","subject":"Re: [PATCH] bash completion: Add completion for 'git grep'","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-08-04T14:53:03Z","receivedAt":"2008-08-04T14:53:03Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Lee Marlow <lee.marlow@gmail.com> wrote:\n> Added completions for all long options specified in the docs\n> \t--cached\n> \t--text --ignore-case --word-regexp --invert-match\n> \t--full-name\n> \t--extended-regexp --basic-regexp --fixed-strings\n> \t--files-with-matches --name-only\n> \t--files-without-match\n> \t--count\n> \t--and --or --not --all-match\n> \n> Signed-off-by: Lee Marlow <lee.marlow@gmail.com>\n\nAcked-by: Shawn O. Pearce <spearce@spearce.org>\n\nThis is the \"first patch\" which has the doubledash test.  As you\npointed out, its better because it stops completion of long options\nafter the --.\n\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 30d8701..b28ac10 100755\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -796,6 +796,29 @@ _git_gc ()\n>  \tCOMPREPLY=()\n>  }\n>  \n> +_git_grep ()\n> +{\n> +\t__git_has_doubledash && return\n> +\n> +\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n> +\tcase \"$cur\" in\n> +\t--*)\n> +\t\t__gitcomp \"\n> +\t\t\t--cached\n> +\t\t\t--text --ignore-case --word-regexp --invert-match\n> +\t\t\t--full-name\n> +\t\t\t--extended-regexp --basic-regexp --fixed-strings\n> +\t\t\t--files-with-matches --name-only\n> +\t\t\t--files-without-match\n> +\t\t\t--count\n> +\t\t\t--and --or --not --all-match\n> +\t\t\t\"\n> +\t\treturn\n> +\t\t;;\n> +\tesac\n> +\tCOMPREPLY=()\n> +}\n> +\n>  _git_help ()\n>  {\n>  \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n> @@ -1486,6 +1509,7 @@ _git ()\n>  \tfetch)       _git_fetch ;;\n>  \tformat-patch) _git_format_patch ;;\n>  \tgc)          _git_gc ;;\n> +\tgrep)        _git_grep ;;\n>  \thelp)        _git_help ;;\n>  \tlog)         _git_log ;;\n>  \tls-remote)   _git_ls_remote ;;\n> -- \n\n-- \nShawn.\n"}]}