ref: 33231f9222486b50e7cfe621fb41a4b7e32e47c1
parent: 4db9bebede2bc066a74231cb28c8828509759683
author: Michael Forney <[email protected]>
date: Sat Jan 1 05:26:14 EST 2022
g: use xargs instead of finding complete file list before greping
--- a/rc/bin/g
+++ b/rc/bin/g
@@ -14,25 +14,24 @@
}
if(~ $1 --)
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)$'
fullnames='(^|/)mkfile$'
switch($#*){
case 0
- echo 'usage: g [flags] pattern [files]' >[1=2]
- exit usage
-case 1
- pattern=$1
- files=`$nl{walk -f $recurse | grep -e $fullnames -e $suffixes >[2]/dev/null}
+ walk -f $recurse | grep -e $fullnames -e $suffixes >[2]/dev/null
case *
- pattern=$1
- shift
for(f in $*){
if(test -d $f)
- files=($files `$nl{walk -f $recurse -- $f \
- | grep -e $fullnames -e $suffixes >[2]/dev/null})
+ walk -f $recurse -- $f \
+ | grep -e $fullnames -e $suffixes >[2]/dev/null
if not
- files=($files $f)
+ echo $f
}
-}
-grep -n $flags -- $pattern $files /dev/null
+} | xargs grep -n $flags -- $pattern