shithub: riscv

ref: 7347012d42284ca11df09be8c68daa2ebc0583a4
dir: /rc/bin/g/

View raw version
#!/bin/rc
rfork e
nl='
'
flags=()
recurse=()
while(! ~ $#* 1 && ~ $1 -* && ! ~ $1 --){
	if(~ $1 '-n')
		recurse=-n1
	if not
		flags=($flags $1);
	shift
}
if(~ $1 --)
	shift

switch($#*){
case 0
	echo 'usage: g [flags] pattern [files]' >[1=2]
	exit usage
case 1
	pattern=$1
	files=`$nl{walk -f $recurse | grep '\.([bcChlmsy]|asm|awk|cc|cgi|cpp|cs|go|goc|java|lx|ms|pl|py|rc|tex|xy)$' >[2]/dev/null}
case *
	pattern=$1
	shift
	files=`$nl{walk -f $recurse -- $*}
}
grep -n $flags -- $pattern $files /dev/null