Browse Source
This allows any arbitrary flags to "grep", and knows about the few special grep flags that take an argument too. It also allows some flags for git-ls-files, although their usefulness is questionable. With this, something line git grep -w -1 pattern works, without the script enumerating every possible flag. [jc: this is the version Linus sent out after I showed him a barf-o-meter test version that avoids shell arrays. He must have typed this version blindly, since he said: I'm not barfing, but that's probably because my brain just shut down and is desperately trying to gouge my eyes out with a spoon. I slightly fixed it to catch the remaining arguments meant to be given git-ls-files.] Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>maint
Linus Torvalds
20 years ago
committed by
Junio C Hamano
1 changed files with 41 additions and 23 deletions
@ -1,25 +1,43 @@ |
|||||||
#!/bin/sh |
#!/bin/sh |
||||||
flags= |
# |
||||||
while :; do |
# Copyright (c) Linus Torvalds, 2005 |
||||||
pattern="$1" |
# |
||||||
case "$pattern" in |
|
||||||
-i|-I|-a|-E|-H|-h|-l) |
pattern= |
||||||
flags="$flags $pattern" |
flags=() |
||||||
shift |
git_flags=() |
||||||
;; |
while : ; do |
||||||
-e) |
case "$1" in |
||||||
pattern="$2" |
--cached|--deleted|--others|--killed|\ |
||||||
shift |
--ignored|--exclude=*|\ |
||||||
break |
--exclude-from=*|\--exclude-per-directory=*) |
||||||
;; |
git_flags=("${git_flags[@]}" "$1") |
||||||
-*) |
;; |
||||||
echo "unknown flag $pattern" >&2 |
-e) |
||||||
exit 1 |
pattern="$2" |
||||||
;; |
shift |
||||||
*) |
;; |
||||||
break |
-A|-B|-C|-D|-d|-f|-m) |
||||||
;; |
flags=("${flags[@]}" "$1" "$2") |
||||||
esac |
shift |
||||||
|
;; |
||||||
|
--) |
||||||
|
# The rest are git-ls-files paths (or flags) |
||||||
|
shift |
||||||
|
break |
||||||
|
;; |
||||||
|
-*) |
||||||
|
flags=("${flags[@]}" "$1") |
||||||
|
;; |
||||||
|
*) |
||||||
|
if [ -z "$pattern" ]; then |
||||||
|
pattern="$1" |
||||||
|
shift |
||||||
|
fi |
||||||
|
break |
||||||
|
;; |
||||||
|
esac |
||||||
|
shift |
||||||
done |
done |
||||||
shift |
git-ls-files -z "${git_flags[@]}" "$@" | |
||||||
git-ls-files -z "$@" | xargs -0 grep $flags -e "$pattern" |
xargs -0 grep "${flags[@]}" "$pattern" |
||||||
|
Loading…
Reference in new issue