shithub: riscv

ref: 81f3b1a233a10fdba00dbeae02fecc2c01d8bca3
dir: /rc/bin/g/

View raw version
#!/bin/rc 
rfork e
flags=() 
while(! ~ $#* 1 && ~ $1 -* && ! ~ $1 --){ 
         flags=($flags $1); 
         shift 
} 
if(~ $1 --) 
         shift 

switch($#*){ 
case 0 
         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}) 
case * 
         pattern=$1 
         shift 
         files=($*) 
} 
grep -n $flags -- $pattern $files /dev/null