plan9fox/rc/bin/g

32 lines
567 B
Text
Raw Normal View History

2019-06-05 05:47:07 +00:00
#!/bin/rc
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
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
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