ref: 7514a153b23e0947a42df1c742395b85112ba775
parent: ee632c1318aafc59dac56ac1d514284cb659d36f
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Nov 21 16:23:46 EST 2020
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}
--- a/rc/bin/g
+++ b/rc/bin/g
@@ -14,6 +14,8 @@
if(~ $1 --)
shift
+suffixes='\.([bcChlmsy]|asm|awk|cc|cgi|cpp|cs|go|goc|hs|java|lx|ms|pl|py|rc|tex|xy)$'
+fullnames='(^|/)mkfile$'
switch($#*){case 0
echo 'usage: g [flags] pattern [files]' >[1=2]
@@ -20,12 +22,16 @@
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 -- $*}+ 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
--
⑨