changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: Make 'g' grep recursively by default.

changeset 7259: 32b0b95f1964
parent 7258: 783d3ae87188
child 7260: 16895cffe792
author: Ori Bernstein <ori@eigenstate.org>
date: Tue, 04 Jun 2019 22:36:32 -0700
files: rc/bin/g sys/man/1/grep
description: Make 'g' grep recursively by default.
     1.1--- a/rc/bin/g
     1.2+++ b/rc/bin/g
     1.3@@ -1,23 +1,29 @@
     1.4 #!/bin/rc 
     1.5 rfork e
     1.6-flags=() 
     1.7-while(! ~ $#* 1 && ~ $1 -* && ! ~ $1 --){ 
     1.8-         flags=($flags $1); 
     1.9-         shift 
    1.10+nl='
    1.11+'
    1.12+flags=()
    1.13+recurse=()
    1.14+while(! ~ $#* 1 && ~ $1 -* && ! ~ $1 --){
    1.15+	if(~ $1 '-n')
    1.16+		recurse=-n1
    1.17+	if not
    1.18+		flags=($flags $1);
    1.19+	shift 
    1.20 } 
    1.21 if(~ $1 --) 
    1.22-         shift 
    1.23+	shift 
    1.24 
    1.25 switch($#*){ 
    1.26 case 0 
    1.27-         echo 'usage: g [flags] pattern [files]' >[1=2] 
    1.28-         exit usage 
    1.29+	echo 'usage: g [flags] pattern [files]' >[1=2] 
    1.30+	exit usage 
    1.31 case 1 
    1.32-         pattern=$1 
    1.33-         files=(`{ls *.[bcChlmsy] *.asm *.awk *.cc *.cgi *.cpp *.cs *.go *.goc *.java *.lx *.ms *.pl *.py *.rc *.tex *.xy >[2]/dev/null}) 
    1.34+	pattern=$1
    1.35+	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}
    1.36 case * 
    1.37-         pattern=$1 
    1.38-         shift 
    1.39-         files=($*) 
    1.40+	pattern=$1 
    1.41+	shift 
    1.42+	files=($*) 
    1.43 } 
    1.44-grep -n $flags -- $pattern $files /dev/null 
    1.45+grep -n $flags -- $pattern $files /dev/null 
    1.46\ No newline at end of file
     2.1--- a/sys/man/1/grep
     2.2+++ b/sys/man/1/grep
     2.3@@ -113,11 +113,16 @@ with
     2.4 .B -n
     2.5 (plus aditional flags, if provided)
     2.6 and forces tagging of output lines by file name. If no files
     2.7-are listed, it searches all files matching
     2.8+are listed, it recursively searches the current directory for
     2.9+all files matching
    2.10 .B *.b *.c *.C *.h *.l *.m *.s *.y
    2.11 .B *.asm *.cc *.cs *.lx *.cgi *.pl
    2.12 .B *.py *.tex *.ms *.java *.xy *.go
    2.13 .B *.goc *.cpp
    2.14+.PP
    2.15+The recursive search can be suppressed by passing g the
    2.16+.B -n
    2.17+flag.
    2.18 .SH SOURCE
    2.19 .B /sys/src/cmd/grep
    2.20 .br