plan9fox/rc/bin/g
2012-07-05 20:24:00 +02:00

23 lines
508 B
Bash

#!/bin/rc
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 *.cc *.cs *.lx *.cgi *.pl *.py *.tex *.ms *.java *.xy *.go *.goc >[2]/dev/null})
case *
pattern=$1
shift
files=($*)
}
grep -n $flags -- $pattern $files /dev/null