]> git.lizzy.rs Git - plan9front.git/commitdiff
Make 'g' grep recursively by default.
authorOri Bernstein <ori@eigenstate.org>
Wed, 5 Jun 2019 05:36:32 +0000 (22:36 -0700)
committerOri Bernstein <ori@eigenstate.org>
Wed, 5 Jun 2019 05:36:32 +0000 (22:36 -0700)
rc/bin/g
sys/man/1/grep

index 69656dfccbe23d24175ece1557ebaef0230d7b9f..10468b3d2ea4e725088682f634b9598dfbc4c48f 100755 (executable)
--- 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
index 433c2370e8ab3329c7b2b0d2dbfca6e498b2d3c0..2a5a98cfae65f2f4cbc66e416cb353bbdf28e9bf 100644 (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