#!/bin/sh
##################################################################
# $Id: ff, v-0.1 : GPL-v2 : 2002/11/24 17:25:45 bish Exp $
# (C) 2002 USM Bish <bish@nde.vsnl.net.in>
# Released under GNU GPL v2 - http://www.gnu.org/copyleft/gpl.html
##################################################################

##################################################################
# Purpose: To scan for a search pattern for any  string within the
# present working directory. List of files  containing  the string
# is the output
##################################################################

##################################################################
#  Constants
##################################################################

PROGNAME=$(basename $0)
VERSION="0.1"
PATTERN=$1

##################################################################
#  Functions
##################################################################

function usage
{
   echo "Usage : $PROGNAME '"[search_string_in_quotes]"'"
}
    
if ! [ "$1" ]; then
   usage
   exit
fi

##################################################################
#  Main routine
##################################################################

echo "$PROGNAME (Find-in_File)     Version-[$VERSION]"
echo
echo -en "Looking for: [$PATTERN] in "
pwd
echo

FILE_LIST=$(echo ./* | xargs grep -l -e $PATTERN 2> /dev/null)

if [ -z "$FILE_LIST" ]; then
   echo "Search pattern : [$PATTERN] not found"
   exit
else   
   CNT=0
   for i in $(echo $FILE_LIST); do
       X=$(file $i | grep "text" 2> /dev/null)
       if ! [ -z "$X" ]; then
          CNT=$((CNT+1))
          echo -en "$CNT] "
          echo `basename $i`
       fi   
   done
fi
exit
    
