ftp.nice.ch/pub/next/unix/shell/findi.1.0.b.tar.gz#/findi.1.0/findi.sh

This is findi.sh in view mode; [Download] [Up]

#!/bin/sh
name=`basename $0`

#############################################################################
# AUTHOR:  Timothy J. Luoma <luomat@capitalist.princeton.edu>
#
# VERSION: 1.0.0
#
# DATE:    09 April 1996
#
# WARNING: USE ENTIRELY AT YOUR OWN RISK
#
# PURPOSE: to make using the extended flags of 'find' a little easier
#		by entering into an interactive mode for some common flags
#
# TESTED UNDER: NeXTStep 3.2 on my NeXTStation
#
# USAGE NOTES:
# 	All arguments given are ignored
#
# 	If you do not want to set any of the options, just hit ENTER
#
# 	It assumes you know _something_ about how 'find' works
#
#	Not all flags are available, basically the ones I like
#
#############################################################################
echo -n "$name: what directory? (Press enter to select current directory) "
read dir

if [ "$dir" = "" ]
then
	dir="."
else
	if [ -d "$dir" ]
	then
		: #placeholder
	else
		echo "$name error: $dir is not a dir, using . "
	fi
fi

######################################################
echo -n "$name: what filename?  (Press enter for ALL) " 
read filename

all=no

if [ "$filename" = "" ]
then
	# filename1="-name *"
	all=yes
else
	filename1="-name $filename"
	
	echo -n "	Only exact matches to $filename? [y/N] " 
		stty cbreak
		wildcard=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
		stty -cbreak

		case $wildcard in
			y|Y) wildcard=no
			;;

			*)   wildcard=yes
			;;
		esac
fi

######################################################
echo "$name: what type?"
echo -n "	(d)irectory (f)ile (l)ink (s)ocket (b)lock (c)haracter (p)ipe -> "
	stty cbreak
	type=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
	stty -cbreak

	case $type in
		b|c|d|f|p|l|s) 
			type1="-type $type"
			echo " "
		;;
		
		*) #no type specified
			type1=""
		;;
	esac

######################################################
echo -n "$name: what user? "
read user

	if [ "$user" = "" ]
	then
		user1=""
	else
		user1="-user $user"
	fi

######################################################
echo -n "$name: last a)ccess m)odified c)hanged? "
	stty cbreak
	amc=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
	stty -cbreak
	
	case $amc in
		a|m|c)  
			echo " "
			echo -n "	how many days? (use + and -) "
			read days
			
			if [ "$amc" = "a" ]
			then
				amc1="-atime $days"
			elif [ "$amc" = "m" ]
			then
				amc1="-mtime $days"
			else
				amc1="-ctime $days"
			fi
		;;
		
		*) amc1=""
		;;
	esac

######################################################

echo -n  "$name: command? (don't end with \;) "
read command

	if [ "$command" != "" ]
	then
		echo -n  "$name: confirm command? [y/N] "
		stty cbreak
		confirm=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
		stty -cbreak
		
		case $confirm in
			y*|Y*) 
			   command1="-ok $command "
			   echo " "
			;;

			*) command1="-exec $command "
			;;
		esac
	fi

######################################################
echo -n "$name: print? [y/N] "
	stty cbreak
	print=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
	stty -cbreak
	
	case $print in 
		
		y|Y) print1="-print"
		     echo " "
		;;
		
		*)   print1=""
		;;
	esac

######################################################
echo -n "$name: list? [y/N] "
	stty cbreak
	list=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
	stty -cbreak
	
	case $list in 
		
		y|Y) list1="-ls"
		     echo " "
		;;
		
		*)   list1=""
		;;
	esac

######################################################
######################################################

if [ "$all" = "yes" ] 	# if the user wants to match all files
then		
	if [ "$command1" != "" ]
	then	
		find $dir -name "*" $type1 $user1 $amc1 $command1 \; $print1 $list1
	else
		find $dir -name "*" $type1 $user1 $amc1 $print1 $list1
	fi
else
	if [ "$wildcard" = "yes" ]
	then
		# if the user DOES NOT want just exact matches
		if [ "$command1" != "" ]
		then	
 		  find $dir $filename1\* $type1 $user1 $amc1 $command1 \; $print1 $list1
		else
  		  find $dir $filename1\* $type1 $user1 $amc1 $print1 $list1
		fi
	else
		# if the user DOES want to use just exact matches
		if [ "$command1" != "" ]
		then	
    		  find $dir $filename1 $type1 $user1 $amc1 $command1 \; $print1 $list1
		else
  		  find $dir $filename1 $type1 $user1 $amc1 $print1 $list1
		fi
	fi
fi

exit 0
# end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.