g: filter directory arguments
When searching directories recursively, it's still desirable to filter the contents by the file pattern, so that 'g foo /sys/src' doesn't end up searching for foo within .$O files. Files passed explicitly are still searched, so for the old behavior, just use walk: g foo `{walk -f $dir}
This commit is contained in:
parent
d1dc287210
commit
97008caa41
1 changed files with 9 additions and 3 deletions
12
rc/bin/g
12
rc/bin/g
|
@ -14,18 +14,24 @@ while(! ~ $#* 1 && ~ $1 -* && ! ~ $1 --){
|
||||||
if(~ $1 --)
|
if(~ $1 --)
|
||||||
shift
|
shift
|
||||||
|
|
||||||
|
suffixes='\.([bcChlmsy]|asm|awk|cc|cgi|cpp|cs|go|goc|hs|java|lx|ms|pl|py|rc|tex|xy)$'
|
||||||
|
fullnames='(^|/)mkfile$'
|
||||||
switch($#*){
|
switch($#*){
|
||||||
case 0
|
case 0
|
||||||
echo 'usage: g [flags] pattern [files]' >[1=2]
|
echo 'usage: g [flags] pattern [files]' >[1=2]
|
||||||
exit usage
|
exit usage
|
||||||
case 1
|
case 1
|
||||||
pattern=$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}
|
files=`$nl{walk -f $recurse | grep -e $fullnames -e $suffixes >[2]/dev/null}
|
||||||
case *
|
case *
|
||||||
pattern=$1
|
pattern=$1
|
||||||
shift
|
shift
|
||||||
files=`$nl{walk -f $recurse -- $*}
|
for(f in $*){
|
||||||
|
if(test -d $f)
|
||||||
|
files=($files `$nl{walk -f $recurse -- $* \
|
||||||
|
| grep -e $fullnames -e $suffixes >[2]/dev/null})
|
||||||
|
if not
|
||||||
|
files=$(files $f)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
grep -n $flags -- $pattern $files /dev/null
|
grep -n $flags -- $pattern $files /dev/null
|
||||||
|
|
Loading…
Reference in a new issue