plan9fox/rc/bin/g
Ori Bernstein 03499e53cc g: add '.hs' and 'mkfile' to the walk. (thanks joe9)
This expands the set of files that we grep through by default to
include mkfiles and haskell.
2020-07-14 20:46:00 -07:00

32 lines
567 B
Bash
Executable file

#!/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
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}
case *
pattern=$1
shift
files=`$nl{walk -f $recurse -- $*}
}
grep -n $flags -- $pattern $files /dev/null