#!/bin/rc
if(! ~ $#* 2){
	echo 'usage: rgrep pattern dir'
	exit
}
p=$1
shift
if(! test -d $1){
	echo 'usage: rgrep pattern dir'
	exit
}

cd $1
# echo checking `{pwd}
for(t in *){
	# echo $t
	if(test -d $t) rgrep $p $t
	v=`{file -m -- $t}
	switch($v){
	case text/*
		grep -s $p $t
		if(! ~ $status ?*){
			w=`{pwd}
			echo $w/$t
		}
	case *
		;
	}
}