diff options
Diffstat (limited to 'bin/g')
-rwxr-xr-x | bin/g | 48 |
1 files changed, 33 insertions, 15 deletions
@@ -1,19 +1,37 @@ -#!/usr/local/plan9/bin/rc +#!/bin/sh -flags=() -while(! ~ $#* 1 && ~ $1 -*){ - flags=($flags $1) - shift -} +inflags=yes +flags="" +while [ $# != 0 -a $inflags = yes ] +do + case "$1" in + -*) + flags="$flags $1" + shift + ;; + -) + inflags=no + shift + ;; + *) + inflags=no + ;; + esac +done -switch($#*){ -case 0 - echo 'usage: g [flags] pattern [files]' >[1=2] +case $# in +0) + echo 1>&2 'usage: g [flags] pattern [files]' exit 1 -case 1 - 9grep -n $flags -- $1 *.[Cbchm] *.cc *.py *.tex *.ms *.java /dev/null \ - |[2] {9grep -v '^(grep: can''t open \*|grep: \*\.)' >[1=2]; status=0} -case * - 9grep -n $flags -- $* /dev/null -} + ;; +1) + pattern="$1" + files=`/bin/ls *.[bcChm] *.cc *.py *.tex *.ms *.java 2>/dev/null` + ;; +*) + pattern="$1" + shift + files="$@" +esac +exec grep -n $flags -- "$pattern" $files /dev/null |