plan9front/rc/bin/g
qwx 084c9d6eba g: add .in, fix earlier fuckup (thanks mkf)
2d63bdbb44 was pushed modified
compared to the patch actually submitted by mkf, in error.
2024-09-04 19:57:16 +00:00

38 lines
758 B
Bash
Executable file

#!/bin/rc
rfork e
nl='
'
flags=()
recurse=()
files=()
while(! ~ $#* 1 && ~ $1 -* && ! ~ $1 --){
if(~ $1 '-n')
recurse=-n1
if not
flags=($flags $1);
shift
}
if(~ $1 --)
shift
if(~ $#* 0) {
echo 'usage: g [flags] pattern [files]' >[1=2]
exit usage
}
pattern=$1
shift
suffixes='\.([bcChlmsSy]|asm|awk|cc|cgi|cpp|cs|cxx|go|goc|ha|hpp|hs|hxx|in|java|lua|lx|mk|ml|mli|ms|myr|pl|py|rc|sh|tex|xy|txt)$'
fullnames='(^|/)mkfile$'
repodirs='(^|/)(.git|.hg)($|/)'
switch($#*){
case 0
walk -f $recurse | grep -e $fullnames -e $suffixes >[2]/dev/null
case *
for(f in $*){
if(test -d $f)
walk -f $recurse -- $f \
| grep -e $fullnames -e $suffixes >[2]/dev/null
if not
echo $f
}
} | grep -v $repodirs | xargs grep -n $flags -- $pattern /dev/null