Make 'g' grep recursively by default.

front
Ori Bernstein 2019-06-04 22:36:32 -07:00
parent 12e136332a
commit 033c2812c2
2 changed files with 25 additions and 14 deletions

View File

@ -1,23 +1,29 @@
#!/bin/rc
rfork e
flags=()
while(! ~ $#* 1 && ~ $1 -* && ! ~ $1 --){
flags=($flags $1);
shift
nl='
'
flags=()
recurse=()
while(! ~ $#* 1 && ~ $1 -* && ! ~ $1 --){
if(~ $1 '-n')
recurse=-n1
if not
flags=($flags $1);
shift
}
if(~ $1 --)
shift
shift
switch($#*){
case 0
echo 'usage: g [flags] pattern [files]' >[1=2]
exit usage
echo 'usage: g [flags] pattern [files]' >[1=2]
exit usage
case 1
pattern=$1
files=(`{ls *.[bcChlmsy] *.asm *.awk *.cc *.cgi *.cpp *.cs *.go *.goc *.java *.lx *.ms *.pl *.py *.rc *.tex *.xy >[2]/dev/null})
pattern=$1
files=`$nl{walk -f $recurse | grep '\.([bcChlmsy]|asm|awk|cc|cgi|cpp|cs|go|goc|java|lx|ms|pl|py|rc|tex|xy)$' >[2]/dev/null}
case *
pattern=$1
shift
files=($*)
pattern=$1
shift
files=($*)
}
grep -n $flags -- $pattern $files /dev/null
grep -n $flags -- $pattern $files /dev/null

View File

@ -113,11 +113,16 @@ with
.B -n
(plus aditional flags, if provided)
and forces tagging of output lines by file name. If no files
are listed, it searches all files matching
are listed, it recursively searches the current directory for
all files matching
.B *.b *.c *.C *.h *.l *.m *.s *.y
.B *.asm *.cc *.cs *.lx *.cgi *.pl
.B *.py *.tex *.ms *.java *.xy *.go
.B *.goc *.cpp
.PP
The recursive search can be suppressed by passing g the
.B -n
flag.
.SH SOURCE
.B /sys/src/cmd/grep
.br