2019-06-05 05:47:07 +00:00
|
|
|
#!/bin/rc
|
2016-03-13 21:34:08 +00:00
|
|
|
rfork e
|
2019-06-05 05:36:32 +00:00
|
|
|
nl='
|
|
|
|
'
|
|
|
|
flags=()
|
|
|
|
recurse=()
|
|
|
|
while(! ~ $#* 1 && ~ $1 -* && ! ~ $1 --){
|
|
|
|
if(~ $1 '-n')
|
|
|
|
recurse=-n1
|
|
|
|
if not
|
|
|
|
flags=($flags $1);
|
2019-06-05 05:47:07 +00:00
|
|
|
shift
|
|
|
|
}
|
|
|
|
if(~ $1 --)
|
|
|
|
shift
|
2011-11-21 16:39:34 +00:00
|
|
|
|
2019-06-05 05:47:07 +00:00
|
|
|
switch($#*){
|
|
|
|
case 0
|
|
|
|
echo 'usage: g [flags] pattern [files]' >[1=2]
|
|
|
|
exit usage
|
|
|
|
case 1
|
2019-06-05 05:36:32 +00:00
|
|
|
pattern=$1
|
2020-07-15 03:46:00 +00:00
|
|
|
fullnames='mkfile$'
|
|
|
|
suffixes='\.([bcChlmsy]|asm|awk|cc|cgi|cpp|cs|go|goc|hs|java|lx|ms|pl|py|rc|tex|xy)$'
|
|
|
|
files=`$nl{walk -f $recurse | grep -e $fullnames -e $suffixes >[2]/dev/null}
|
2019-06-05 05:47:07 +00:00
|
|
|
case *
|
|
|
|
pattern=$1
|
|
|
|
shift
|
2020-02-27 05:45:00 +00:00
|
|
|
files=`$nl{walk -f $recurse -- $*}
|
2019-06-05 05:47:07 +00:00
|
|
|
}
|
2019-06-05 05:42:10 +00:00
|
|
|
grep -n $flags -- $pattern $files /dev/null
|