Make 'g' grep recursively by default.
This commit is contained in:
parent
12e136332a
commit
033c2812c2
2 changed files with 25 additions and 14 deletions
32
rc/bin/g
32
rc/bin/g
|
@ -1,23 +1,29 @@
|
||||||
#!/bin/rc
|
#!/bin/rc
|
||||||
rfork e
|
rfork e
|
||||||
flags=()
|
nl='
|
||||||
while(! ~ $#* 1 && ~ $1 -* && ! ~ $1 --){
|
'
|
||||||
flags=($flags $1);
|
flags=()
|
||||||
shift
|
recurse=()
|
||||||
|
while(! ~ $#* 1 && ~ $1 -* && ! ~ $1 --){
|
||||||
|
if(~ $1 '-n')
|
||||||
|
recurse=-n1
|
||||||
|
if not
|
||||||
|
flags=($flags $1);
|
||||||
|
shift
|
||||||
}
|
}
|
||||||
if(~ $1 --)
|
if(~ $1 --)
|
||||||
shift
|
shift
|
||||||
|
|
||||||
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
|
||||||
files=(`{ls *.[bcChlmsy] *.asm *.awk *.cc *.cgi *.cpp *.cs *.go *.goc *.java *.lx *.ms *.pl *.py *.rc *.tex *.xy >[2]/dev/null})
|
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 *
|
case *
|
||||||
pattern=$1
|
pattern=$1
|
||||||
shift
|
shift
|
||||||
files=($*)
|
files=($*)
|
||||||
}
|
}
|
||||||
grep -n $flags -- $pattern $files /dev/null
|
grep -n $flags -- $pattern $files /dev/null
|
|
@ -113,11 +113,16 @@ with
|
||||||
.B -n
|
.B -n
|
||||||
(plus aditional flags, if provided)
|
(plus aditional flags, if provided)
|
||||||
and forces tagging of output lines by file name. If no files
|
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 *.b *.c *.C *.h *.l *.m *.s *.y
|
||||||
.B *.asm *.cc *.cs *.lx *.cgi *.pl
|
.B *.asm *.cc *.cs *.lx *.cgi *.pl
|
||||||
.B *.py *.tex *.ms *.java *.xy *.go
|
.B *.py *.tex *.ms *.java *.xy *.go
|
||||||
.B *.goc *.cpp
|
.B *.goc *.cpp
|
||||||
|
.PP
|
||||||
|
The recursive search can be suppressed by passing g the
|
||||||
|
.B -n
|
||||||
|
flag.
|
||||||
.SH SOURCE
|
.SH SOURCE
|
||||||
.B /sys/src/cmd/grep
|
.B /sys/src/cmd/grep
|
||||||
.br
|
.br
|
||||||
|
|
Loading…
Reference in a new issue