{"thread":{"id":"1785","subject":"Add \"git grep\" helper","startedAt":"2005-09-12T19:06:10Z","lastAt":"2005-09-13T00:51:56Z","messageCount":13,"participants":["Linus Torvalds","Morten Welinder","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"8411","messageId":"Pine.LNX.4.58.0509121203210.4098@g5.osdl.org","threadId":"1785","inReplyTo":null,"subject":"Add \"git grep\" helper","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-09-12T19:06:10Z","receivedAt":"2005-09-12T19:06:10Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nVery convenient shorthand for\n\n\tgit-ls-files [file-patterns] | xargs grep <pattern>\n\nwhich I tend to do all the time.\n\nYes, it's trivial, but it's really nice. I can do\n\n\tgit grep '\\<some_variable\\>' arch/i386 include/asm-i386\n\nand it does exactly what you'd think it does. And since it just uses the \nnormal git-ls-files file patterns, you can do things like\n\n\tgit grep something 'include/*.h'\n\nand it will search all header files under the include/ subdirectory.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\ndiff --git a/Makefile b/Makefile\n--- a/Makefile\n+++ b/Makefile\n@@ -76,7 +76,7 @@ SCRIPT_SH = \\\n \tgit-tag.sh git-verify-tag.sh git-whatchanged.sh git.sh \\\n \tgit-applymbox.sh git-applypatch.sh \\\n \tgit-merge.sh git-merge-stupid.sh git-merge-octopus.sh \\\n-\tgit-merge-resolve.sh\n+\tgit-merge-resolve.sh git-grep.sh\n \n SCRIPT_PERL = \\\n \tgit-archimport.perl git-cvsimport.perl git-relink.perl \\\ndiff --git a/git-grep.sh b/git-grep.sh\nnew file mode 100755\n--- /dev/null\n+++ b/git-grep.sh\n@@ -0,0 +1,20 @@\n+#!/bin/sh\n+flags=\n+while :; do\n+  pattern=\"$1\"\n+  case \"$pattern\" in\n+  -i|-I|-a|-E|-H|-h|-l)\n+    flags=\"$flags $pattern\"\n+    shift\n+    ;;\n+  -*)\n+    echo \"unknown flag $pattern\" >&2\n+    exit 1\n+    ;;\n+  *)\n+    break\n+    ;;\n+  esac\n+done\n+shift\n+git-ls-files -z \"$@\" | xargs -0 grep $flags \"$pattern\"\n"},{"id":"8422","messageId":"118833cc0509121357698005fe@mail.gmail.com","threadId":"1785","inReplyTo":"Pine.LNX.4.58.0509121203210.4098@g5.osdl.org","subject":"Re: Add \"git grep\" helper","fromName":"Morten Welinder","fromEmail":"mwelinder@gmail.com","sentAt":"2005-09-12T20:57:56Z","receivedAt":"2005-09-12T20:57:56Z","isPatch":false,"sender":{"key":"mwelinder@gmail.com","avatar":null},"body":"Cute, but what about grep flags like \"-w\", \"-n\", and \"-c\"?\n\nM.\n"},{"id":"8432","messageId":"Pine.LNX.4.58.0509121434410.3266@g5.osdl.org","threadId":"1785","inReplyTo":"118833cc0509121357698005fe@mail.gmail.com","subject":"Re: Add \"git grep\" helper","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-09-12T21:37:28Z","receivedAt":"2005-09-12T21:37:28Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 12 Sep 2005, Morten Welinder wrote:\n>\n> Cute, but what about grep flags like \"-w\", \"-n\", and \"-c\"?\n\nHey, add them to the flags list. Or just pass in all flags to grep, I\ndunno (I was kind of expecting some flags to go to git-ls-files, but that\nmay or may not make any sense, and my script obviously didn't end up doing\nthat).\n\n\t\tLinus\n"},{"id":"8435","messageId":"7vbr2y7yfd.fsf@assigned-by-dhcp.cox.net","threadId":"1785","inReplyTo":"Pine.LNX.4.58.0509121203210.4098@g5.osdl.org","subject":"Re: Add \"git grep\" helper","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-12T21:45:26Z","receivedAt":"2005-09-12T21:45:26Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@osdl.org> writes:\n\n> Very convenient shorthand for\n>\n> \tgit-ls-files [file-patterns] | xargs grep <pattern>\n>\n> which I tend to do all the time.\n\nGreat minds think alike.  I stopped using 'grep-find' in Emacs\nand use \"git-ls-fiels -z | xargs -0 grep\" instead these days.\nThanks for the patch; applied.\n\nI do not much care about other grep flags but I think you forgot\nto special case '-e', so what is in the \"master\" branch has one\nextra commit on top of it for that (it does not seem to have\npercolated down yet).\n"},{"id":"8437","messageId":"Pine.LNX.4.58.0509121500400.3266@g5.osdl.org","threadId":"1785","inReplyTo":"7vbr2y7yfd.fsf@assigned-by-dhcp.cox.net","subject":"Re: Add \"git grep\" helper","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-09-12T22:12:32Z","receivedAt":"2005-09-12T22:12:32Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 12 Sep 2005, Junio C Hamano wrote:\n> \n> I do not much care about other grep flags but I think you forgot\n> to special case '-e', so what is in the \"master\" branch has one\n> extra commit on top of it for that (it does not seem to have\n> percolated down yet).\n\nActually, the more I think about it, the more I think Morten was right, \nand the git-grep case statement should just put all flags in \"$flags\", and \nany git-ls-files flags can be handled specially before.\n\nWe also need special casing for grep flags that take an argument.  So the\nend result might be something like the following..\n\n  ...\n  case \"$pattern\" in\n\n    # git-ls-file specific flags\n    --others|--exclude=*|--exclude-from=*|--exclude-per-directory=*)\n\tgit_flags=\"$git_flags $pattern\"\n\tshift\n\t;;\n\n    # grep flags with an argument\n    -B|-C|-m)\n\tflags=\"$flags $pattern $2\"\n\tshift\n\tshift\n\t;;\n\n    # grep 'pattern' argument\n    -e)\n\tpattern=\"$2\"\n\tshift\n\tbreak\n\t;;\n\n    # We assume everything else is a regular grep pattern\n    -*)\n\tflags=\"$flags $pattern\"\n\tshift\n\t;;\n  ...\n\ninstead. And it's entirely possible that we'd never want to even bother \nwith things like --others and --exclude* at all.\n\n\t\tLinus\n"},{"id":"8438","messageId":"Pine.LNX.4.58.0509121519310.3266@g5.osdl.org","threadId":"1785","inReplyTo":"Pine.LNX.4.58.0509121500400.3266@g5.osdl.org","subject":"Improve \"git grep\" flags handling","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-09-12T22:22:44Z","receivedAt":"2005-09-12T22:22:44Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nThis allows any arbitrary flags to \"grep\", and knows about the few special \ngrep flags that take an argument too.\n\nIt also allows some flags for git-ls-files, although their usefulness is \nquestionable.\n\nWith this, something line\n\n\tgit grep -w -1 pattern\n\nworks, without the script enumerating every possible flag.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\nOn Mon, 12 Sep 2005, Linus Torvalds wrote:\n> \n> We also need special casing for grep flags that take an argument.  So the\n> end result might be something like the following..\n\ndiff --git a/git-grep.sh b/git-grep.sh\n--- a/git-grep.sh\n+++ b/git-grep.sh\n@@ -1,25 +1,38 @@\n #!/bin/sh\n flags=\n+git_flags=\n while :; do\n   pattern=\"$1\"\n   case \"$pattern\" in\n-  -i|-I|-a|-E|-H|-h|-l)\n-    flags=\"$flags $pattern\"\n-    shift\n-    ;;\n+  # git-ls-file specific flags\n+  --others|--exclude=*|--exclude-from=*|--exclude-per-directory=*)\n+      git_flags=\"$git_flags $pattern\"\n+      shift\n+      ;;\n+\n+  # grep flags with an argument\n+  -B|-C|-m)\n+      flags=\"$flags $pattern $2\"\n+      shift\n+      shift\n+      ;;\n+\n+  # grep 'pattern' argument\n   -e)\n-    pattern=\"$2\"\n-    shift\n-    break\n-    ;;\n+      pattern=\"$2\"\n+      shift\n+      break\n+      ;;\n+\n+  # We assume everything else is a regular grep pattern\n   -*)\n-    echo \"unknown flag $pattern\" >&2\n-    exit 1\n-    ;;\n+      flags=\"$flags $pattern\"\n+      shift\n+      ;;\n   *)\n     break\n     ;;\n   esac\n done\n shift\n-git-ls-files -z \"$@\" | xargs -0 grep $flags -e \"$pattern\"\n+git-ls-files -z $git_flags \"$@\" | xargs -0 grep $flags -e \"$pattern\"\n"},{"id":"8439","messageId":"7virx57w9t.fsf@assigned-by-dhcp.cox.net","threadId":"1785","inReplyTo":"Pine.LNX.4.58.0509121500400.3266@g5.osdl.org","subject":"Re: Add \"git grep\" helper","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-12T22:31:58Z","receivedAt":"2005-09-12T22:31:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@osdl.org> writes:\n\n> Actually, the more I think about it, the more I think Morten was right, \n> and the git-grep case statement should just put all flags in \"$flags\", and \n> any git-ls-files flags can be handled specially before.\n>\n> We also need special casing for grep flags that take an argument.  So the\n> end result might be something like the following..\n\nArrrrrrrrrrrrrrrrrrrgh.\n\nNow, whose grep are we going to support?  Should we teach every\nflag GNU grep supports that can take a parameter to the script?\n\nCan we cheat and do something like this instead?\n\n    git grep -B 6 -A 2 frotz -- arch/i386\n    git grep -B 6 -A 2 frotz --others arch/i386\n\nThat is, things up to a known git-ls-files flag  or -- are\npassed to grep and the rest is given to git-ls-files.\n"},{"id":"8440","messageId":"7vd5nd7w0x.fsf@assigned-by-dhcp.cox.net","threadId":"1785","inReplyTo":"Pine.LNX.4.58.0509121519310.3266@g5.osdl.org","subject":"Re: Improve \"git grep\" flags handling","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-12T22:37:18Z","receivedAt":"2005-09-12T22:37:18Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@osdl.org> writes:\n\n> +  # git-ls-file specific flags\n> +  --others|--exclude=*|--exclude-from=*|--exclude-per-directory=*)\n> +      git_flags=\"$git_flags $pattern\"\n> +      shift\n> +      ;;\n\nThis would not fly well, I am afraid.  --exclude=* are usually\nshell globs which would be expanded before you use them\nunquoted.\n"},{"id":"8442","messageId":"Pine.LNX.4.58.0509121542050.3266@g5.osdl.org","threadId":"1785","inReplyTo":"7vd5nd7w0x.fsf@assigned-by-dhcp.cox.net","subject":"Re: Improve \"git grep\" flags handling","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-09-12T22:43:52Z","receivedAt":"2005-09-12T22:43:52Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 12 Sep 2005, Junio C Hamano wrote:\n> \n> This would not fly well, I am afraid.  --exclude=* are usually\n> shell globs which would be expanded before you use them\n> unquoted.\n\nGood point. However, since it's unlikely that anybody will use it, maybe \nit's not important - more of a \"this is how you could do it if you fixed \nthe globbing problem\" ;)\n\nIt's easy enough to fix if you use bash array variables, but I thought \nadding that was not supposed to be done? Or have people resigned \nthemselves to bash extensions ;)\n\n\t\tLinus\n"},{"id":"8446","messageId":"7vslw96f6j.fsf@assigned-by-dhcp.cox.net","threadId":"1785","inReplyTo":"Pine.LNX.4.58.0509121542050.3266@g5.osdl.org","subject":"Re: Improve \"git grep\" flags handling","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-12T23:26:28Z","receivedAt":"2005-09-12T23:26:28Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@osdl.org> writes:\n\n> Good point. However, since it's unlikely that anybody will use it, maybe \n> it's not important - more of a \"this is how you could do it if you fixed \n> the globbing problem\" ;)\n\nYeah, let's see how tolerant your barf-o-meter is today.  This\nwould make even *me* barf ;-), but it sometimes may be useful to\nbe able to say:\n\n    git grep --others --exclude='*.[oa]' '@@GIT_'\n\n------------\n#!/bin/sh\n\n# git grep <flags>... <pattern> <path>...\n\n{\n    # Pick ls-files arguments only.\n    first=yes skip=no pattern_found=no\n    for x\n    do\n\tcase \"$skip\" in yes) skip=no; continue ;; esac \n    \tcase \"$x\" in\n\t--cached|--deleted|--others|--killed|--ignored|--exclude=*|\\\n\t--exclude-from=*|\\--exclude-per-directory=*)\n\t\ttest 'yes' = \"$first\" && set x\n\t\tset \"$@\" \"$x\"\n\t\tfirst=no\n\t\t;;\n\t-A|-B|-C|-D|-d|-f|-m)\n\t\tskip=yes\n\t\t;;\n\t-e)\n\t\tskip=yes\n\t\tpattern_found=yes\n\t\t;;\n\t-*)\n\t\t;;\n\t*)\n\t\tcase \"$pattern_found\" in\n\t\tyes)\n\t\t\ttest 'yes' = \"$first\" && set x\n\t\t\tset \"$@\" \"$x\"\n\t\t\t;;\n\t\tno)\n\t\t\t;; # not for us, but for grep\n\t\tesac\n\t\t;;\n\tesac\n    done\n    case \"$first\" in\n    yes) # we did not get *any* ls-files parameter.\n    \tset x ;;\n    esac\n    shift\n    git-ls-files -z \"$@\"\n} | {\n    first=yes eat=no pattern_found=no\n    for x\n    do\n\tcase \"$eat\" in\n\tyes)\n\t\teat=no;\n\t\tset \"$@\" \"$x\"\n\t\tcontinue\n\t\t;;\n\tesac \n    \tcase \"$x\" in\n\t--cached|--deleted|--others|--killed|--ignored|--exclude=*|\\\n\t--exclude-from=*|\\--exclude-per-directory=*)\n\t\t;;\n\t-A|-B|-C|-D|-d|-f|-m)\n\t\ttest 'yes' = \"$first\" && set x\n\t\tset \"$@\" \"$x\"\n\t\tfirst=no\n\t\teat=yes\n\t\t;;\n\t-e)\n\t\ttest 'yes' = \"$first\" && set x\n\t\tset \"$@\" \"$x\"\n\t\teat=yes\n\t\tpattern_found=yes\n\t\t;;\n\t-*)\n\t\ttest 'yes' = \"$first\" && set x\n\t\tset \"$@\" \"$x\"\n\t\tfirst=no\n\t\t;;\n\t*)\n\t\tcase \"$pattern_found\" in\n\t\tyes)\n\t\t\t;; # not for us, but for ls-files\n\t\tno)\n\t\t\ttest 'yes' = \"$first\" && set x\n\t\t\tset \"$@\" \"$x\"\n\t\t\tpattern_found=yes\n\t\tesac\n\t\t;;\n\tesac\n    done\n    case \"$eat,$pattern_found\" in\n    yes,* | *,no)\n    \techo >&2 \"* malformed grep parameters\"\n\texit 1\n    esac\n    shift\n    xargs -0 grep \"$@\"\n}\n"},{"id":"8447","messageId":"Pine.LNX.4.58.0509121635060.3266@g5.osdl.org","threadId":"1785","inReplyTo":"7vslw96f6j.fsf@assigned-by-dhcp.cox.net","subject":"Re: Improve \"git grep\" flags handling","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-09-12T23:46:53Z","receivedAt":"2005-09-12T23:46:53Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 12 Sep 2005, Junio C Hamano wrote:\n> \n> Yeah, let's see how tolerant your barf-o-meter is today.\n\nI'm not barfing, but that's probably because my brain just shut down and \nis desperately trying to gouge my eyes out with a spoon.\n\nWouldn't it be _much_ nicer to just do\n\n\tpattern=\n\tflags=()\n\tgit_flags=()\n\twhile : ; do\n\t\tcase \"$1\" in\n\t\t--cached|--deleted|--others|--killed|\\\n\t\t--ignored|--exclude=*|\\\n\t\t--exclude-from=*|\\--exclude-per-directory=*)\n\t\t\tgit_flags=(\"${git_flags[@]}\" \"$1\")\n\t\t\t;;\n\t\t-e)\n\t\t\tpattern=\"$2\"\n\t\t\tshift\n\t\t\t;;\n\t\t-A|-B|-C|-D|-d|-f|-m)\n\t\t\tflags=(\"${flags[@]}\" \"$1\" \"$2\")\n\t\t\tshift\n\t\t\t;;\n\t\t--)\n\t\t\tshift\n\t\t\tbreak\n\t\t\t;;\n\t\t-*)\n\t\t\tflags=(\"${flags[@]}\" \"$1\")\n\t\t\t;;\n\t\t*)\n\t\t\tif [ -z \"$pattern\" ]; then\n\t\t\t\tpattern=\"$1\"\n\t\t\t\tshift\n\t\t\tfi\n\t\t\tbreak\n\t\t\t;;\n\t\tesac\n\t\tshift\n\tdone\n\tgit-ls-files -z \"${git_flags[@]}\" | \n\t\txargs -0 grep \"${flags[@]}\" \"$pattern\"\n\nwhich does use bash array variables, but dang, it does so for a reason: \nthey really are very very useful, and they make it _so_ much more pleasant \nto do these things..\n\n\t\tLinus\n"},{"id":"8449","messageId":"7voe6x6dug.fsf@assigned-by-dhcp.cox.net","threadId":"1785","inReplyTo":"Pine.LNX.4.58.0509121635060.3266@g5.osdl.org","subject":"Re: Improve \"git grep\" flags handling","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-12T23:55:19Z","receivedAt":"2005-09-12T23:55:19Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@osdl.org> writes:\n\n> On Mon, 12 Sep 2005, Junio C Hamano wrote:\n>> \n>> Yeah, let's see how tolerant your barf-o-meter is today.\n>\n> I'm not barfing, but that's probably because my brain just shut down and \n> is desperately trying to gouge my eyes out with a spoon.\n>\n> Wouldn't it be _much_ nicer to just do\n\nYes.\n"},{"id":"8454","messageId":"7v64t56b83.fsf_-_@assigned-by-dhcp.cox.net","threadId":"1785","inReplyTo":"Pine.LNX.4.58.0509121635060.3266@g5.osdl.org","subject":"[PATCH] Improve \"git grep\" flags handling","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-13T00:51:56Z","receivedAt":"2005-09-13T00:51:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This allows any arbitrary flags to \"grep\", and knows about the few\nspecial grep flags that take an argument too.\n\nIt also allows some flags for git-ls-files, although their usefulness\nis questionable.\n\nWith this, something line\n\n\tgit grep -w -1 pattern\n\nworks, without the script enumerating every possible flag.\n\n[jc: this was the version after I showed Linus a barf-o-meter test\n version that avoids shell arrays.  The emperor penguin must have\n typed this version blindly, since he said:\n\n    I'm not barfing, but that's probably because my brain just shut\n    down and is desperately trying to gouge my eyes out with a spoon.\n\n I slightly fixed it to catch the remaining arguments meant to be\n given git-ls-files.]\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n    Linus Torvalds <torvalds@osdl.org> writes:\n\n    Wouldn't it be _much_ nicer to just do which does use bash\n    array variables, but dang, it does so for a reason: they\n    really are very very useful, and they make it _so_ much more\n    pleasant to do these things..\n\n Thanks, Linus.  This is what will go into \"master\" tonight.\n\n git-grep.sh |   64 ++++++++++++++++++++++++++++++++++++++---------------------\n 1 files changed, 41 insertions(+), 23 deletions(-)\n\n6df4eef9b10c8de2b9bc3dc769f3a008a1200df7\ndiff --git a/git-grep.sh b/git-grep.sh\n--- a/git-grep.sh\n+++ b/git-grep.sh\n@@ -1,25 +1,43 @@\n #!/bin/sh\n-flags=\n-while :; do\n-  pattern=\"$1\"\n-  case \"$pattern\" in\n-  -i|-I|-a|-E|-H|-h|-l)\n-    flags=\"$flags $pattern\"\n-    shift\n-    ;;\n-  -e)\n-    pattern=\"$2\"\n-    shift\n-    break\n-    ;;\n-  -*)\n-    echo \"unknown flag $pattern\" >&2\n-    exit 1\n-    ;;\n-  *)\n-    break\n-    ;;\n-  esac\n+#\n+# Copyright (c) Linus Torvalds, 2005\n+#\n+\n+pattern=\n+flags=()\n+git_flags=()\n+while : ; do\n+\tcase \"$1\" in\n+\t--cached|--deleted|--others|--killed|\\\n+\t--ignored|--exclude=*|\\\n+\t--exclude-from=*|\\--exclude-per-directory=*)\n+\t\tgit_flags=(\"${git_flags[@]}\" \"$1\")\n+\t\t;;\n+\t-e)\n+\t\tpattern=\"$2\"\n+\t\tshift\n+\t\t;;\n+\t-A|-B|-C|-D|-d|-f|-m)\n+\t\tflags=(\"${flags[@]}\" \"$1\" \"$2\")\n+\t\tshift\n+\t\t;;\n+\t--)\n+\t\t# The rest are git-ls-files paths (or flags)\n+\t\tshift\n+\t\tbreak\n+\t\t;;\n+\t-*)\n+\t\tflags=(\"${flags[@]}\" \"$1\")\n+\t\t;;\n+\t*)\n+\t\tif [ -z \"$pattern\" ]; then\n+\t\t\tpattern=\"$1\"\n+\t\t\tshift\n+\t\tfi\n+\t\tbreak\n+\t\t;;\n+\tesac\n+\tshift\n done\n-shift\n-git-ls-files -z \"$@\" | xargs -0 grep $flags -e \"$pattern\"\n+git-ls-files -z \"${git_flags[@]}\" \"$@\" |\n+\txargs -0 grep \"${flags[@]}\" \"$pattern\"\n"}]}