#!/bin/csh
# http://www.berklix.com/~jhs/bin/.csh/Grep
# by Julian H. Stacey
# Purpose: find + grep for a text string in current directory & sub dirs.

# Written before I knew of glimpse:
#   http://github.com/gvelez17/glimpse/blob/master/README
#   glimpse was referred to in 
#     http://www.redhat.com/mailman/listinfo/exmh-users
#	Subject: Re: Is anybody still using these features?
#	To: Discussion list for EXMH users <exmh-users@redhat.com>
#	Cc: exmh-workers@redhat.com
#	Date: Wed, 19 Dec 2018 09:45:16 +1000
#	
#   FreeBSD-9.2_RELEASE has /usr/ports/textproc/glimpse 
#   its gone in 13.0-CURRENT 2018-12-19.

# The ref. to SCO suggests this was written decades ago, 
# maybe 1993 @ hof str, or 1999 @ OCE < CV)

# At 2020-12 FreeBSD 9.2-RELEASE & 12.2-STABLE support grep -R, -r, --recursive
# making this script pretty much redundant
# (except the script does avoid spaces, 
# & may be useful if working on other vintage Unixes).

set ab = `uname`
if ( x.$ab != x.SCO_SV ) then	# {
	set and="-and"	# for BSD
else					# }{
	set and=""	# for uname=SCO_SV
	# man find < SCO:
	#  Note that placing two primaries next to each other is the
	#  equivalent of the logical ``and'' operation. The precedence of
	#  this operation is less than that of the ``!'' operator but
	#  greater than that of the -o operator.
endif					# }
find . -type f \( \
	\! -name \*.a		$and \
	\! -name \*.afm		$and \
	\! -name \*.com		$and \
	\! -name \*.core	$and \
	\! -name \*.db		$and \
	\! -name \*.eps		$and \
	\! -name \*.exe		$and \
	\! -name \*.gif		$and \
	\! -name \*.gsf		$and \
	\! -name \*.gz		$and \
	\! -name \*.jpg		$and \
	\! -name \*.lrz		$and \
	\! -name \*.o		$and \
	\! -name \*.pcl		$and \
	\! -name \*.pfa		$and \
	\! -name \*.pfb		$and \
	\! -name \*.pfm		$and \
	\! -name \*.ps		$and \
	\! -name \*.tar.gz	$and \
	\! -name \*.tgz		$and \
	\! -name \*.tiff	$and \
	\! -name \*~		\
	\) -print0 | xargs -0 grep -i "$1"
# The -0 stuff is to cope with disgusting names, EG
#	.pgp/.matchcache.PGP 2.6
#	.pgp/.matchcache.PGP 5.0
# Some damn ignorant Microsoft programmers & users putting spaces in
# file names - sigh !

