1290c534be
When grep gets a single file argument, it does not show the file name. This makes seeing the file name in the output of 'g' difficult. Pass a spare /dev/null to each invocation of g, in order to force it to show the file name.
38 lines
735 B
Bash
Executable file
38 lines
735 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='\.([bcChlmsy]|asm|awk|cc|cgi|cpp|cs|go|goc|hs|java|lua|lx|mk|ml|mli|ms|myr|pl|py|rc|sh|tex|xy)$'
|
|
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
|