ref: 033c2812c29b0e81e6c055b80e0334ba5ed1f871
parent: 12e136332a7dcb6e4d0b4a85fef9ff97dfa57200
author: Ori Bernstein <[email protected]>
date: Tue Jun 4 18:36:32 EDT 2019
Make 'g' grep recursively by default.
--- a/rc/bin/g
+++ b/rc/bin/g
@@ -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
\ No newline at end of file
--- a/sys/man/1/grep
+++ b/sys/man/1/grep
@@ -113,11 +113,16 @@
.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