g: use xargs instead of finding complete file list before greping
This commit is contained in:
parent
4db9bebede
commit
33231f9222
1 changed files with 11 additions and 12 deletions
23
rc/bin/g
23
rc/bin/g
|
@ -14,25 +14,24 @@ while(! ~ $#* 1 && ~ $1 -* && ! ~ $1 --){
|
||||||
}
|
}
|
||||||
if(~ $1 --)
|
if(~ $1 --)
|
||||||
shift
|
shift
|
||||||
|
if(~ $#* 0) {
|
||||||
|
echo 'usage: g [flags] pattern [files]' >[1=2]
|
||||||
|
exit usage
|
||||||
|
}
|
||||||
|
pattern=$1
|
||||||
|
shift
|
||||||
|
|
||||||
suffixes='\.([bcChlmsy]|asm|awk|cc|cgi|cpp|cs|go|goc|hs|java|lua|lx|mk|ml|mli|ms|myr|pl|py|rc|sh|tex|xy)$'
|
suffixes='\.([bcChlmsy]|asm|awk|cc|cgi|cpp|cs|go|goc|hs|java|lua|lx|mk|ml|mli|ms|myr|pl|py|rc|sh|tex|xy)$'
|
||||||
fullnames='(^|/)mkfile$'
|
fullnames='(^|/)mkfile$'
|
||||||
switch($#*){
|
switch($#*){
|
||||||
case 0
|
case 0
|
||||||
echo 'usage: g [flags] pattern [files]' >[1=2]
|
walk -f $recurse | grep -e $fullnames -e $suffixes >[2]/dev/null
|
||||||
exit usage
|
|
||||||
case 1
|
|
||||||
pattern=$1
|
|
||||||
files=`$nl{walk -f $recurse | grep -e $fullnames -e $suffixes >[2]/dev/null}
|
|
||||||
case *
|
case *
|
||||||
pattern=$1
|
|
||||||
shift
|
|
||||||
for(f in $*){
|
for(f in $*){
|
||||||
if(test -d $f)
|
if(test -d $f)
|
||||||
files=($files `$nl{walk -f $recurse -- $f \
|
walk -f $recurse -- $f \
|
||||||
| grep -e $fullnames -e $suffixes >[2]/dev/null})
|
| grep -e $fullnames -e $suffixes >[2]/dev/null
|
||||||
if not
|
if not
|
||||||
files=($files $f)
|
echo $f
|
||||||
}
|
}
|
||||||
}
|
} | xargs grep -n $flags -- $pattern
|
||||||
grep -n $flags -- $pattern $files /dev/null
|
|
||||||
|
|
Loading…
Reference in a new issue