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=()
|
2020-12-19 12:33:11 +00:00
|
|
|
files=()
|
2019-06-05 05:36:32 +00:00
|
|
|
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
|
2022-01-01 10:26:14 +00:00
|
|
|
if(~ $#* 0) {
|
|
|
|
echo 'usage: g [flags] pattern [files]' >[1=2]
|
|
|
|
exit usage
|
|
|
|
}
|
|
|
|
pattern=$1
|
|
|
|
shift
|
2011-11-21 16:39:34 +00:00
|
|
|
|
2021-04-09 01:18:53 +00:00
|
|
|
suffixes='\.([bcChlmsy]|asm|awk|cc|cgi|cpp|cs|go|goc|hs|java|lua|lx|mk|ml|mli|ms|myr|pl|py|rc|sh|tex|xy)$'
|
2020-11-22 05:23:46 +00:00
|
|
|
fullnames='(^|/)mkfile$'
|
2022-02-05 00:40:45 +00:00
|
|
|
repodirs='(^|/)(.git|.hg)($|/)'
|
2019-06-05 05:47:07 +00:00
|
|
|
switch($#*){
|
|
|
|
case 0
|
2022-01-01 10:26:14 +00:00
|
|
|
walk -f $recurse | grep -e $fullnames -e $suffixes >[2]/dev/null
|
2019-06-05 05:47:07 +00:00
|
|
|
case *
|
2020-11-22 05:23:46 +00:00
|
|
|
for(f in $*){
|
|
|
|
if(test -d $f)
|
2022-01-01 10:26:14 +00:00
|
|
|
walk -f $recurse -- $f \
|
|
|
|
| grep -e $fullnames -e $suffixes >[2]/dev/null
|
2020-11-22 05:23:46 +00:00
|
|
|
if not
|
2022-01-01 10:26:14 +00:00
|
|
|
echo $f
|
2020-11-22 05:23:46 +00:00
|
|
|
}
|
2022-02-05 00:40:45 +00:00
|
|
|
} | grep -v $repodirs | xargs grep -n $flags -- $pattern /dev/null
|