#!/bin/sh 

FILESPEC=$1

PROMPT="Command: "

while echo "Building file list for `pwd`"
do
	if [ X$FILESPEC = "X" ] ; then
		FILELIST=`ls -AadF .* ; ls -AadF *`
	else
		FILELIST=`ls -AadF $FILESPEC`
	fi

	for FILE in ${FILELIST}
	do
		LS=`ls -AadFlg ${FILE}`
		while echo ${LS} ; echo -n "${DEST+[$DEST ]}$PROMPT" ; read COMMAND ARG1 ARGX
		do
			echo
			case ${COMMAND} in
				-) echo ${FILELIST} ;;
				q) exit ;;
				n) break ;;
				$) break 2 ;;

				r) rm ${FILE} ; break ;;
				v) more ${FILE} ;;

				c) if [ X$ARG1 = "X" ] ; then echo "Missing destination pathname!" ; else cp ${FILE} $ARG1 ; fi ;;
				m) if [ X$ARG1 = "X" ] ; then echo "Missing destination pathname!" ; else mv $FILE $ARG1 ; break ; fi ;;

				dest) unset DEST ; DEST=${ARG1} ; echo "Destination directory for \".\" commands set to: $DEST" ;;

				.c) if [ X$DEST = "X" ] ; then echo "Dest. directory not set!" ; else cp $FILE $DEST ; fi ;;
				.m) if [ X$DEST = "X" ] ; then echo "Dest. directory not set!" ; else mv $FILE $DEST ; break ; fi ;;

				!) ( ${ARG1} ${ARGX} ) ;;

				?) echo "Commands are:"
				echo "r                  rm (file) "
				echo "v                  more (file) "
                                echo "c  destination     cp (file) destination"
                                echo "m  destination     mv (file) destination"
                                echo 
                                echo "dest pathname      set (dest) directory for \".\" commands below"
                                echo ".c                 cp (file) (dest)"
                                echo ".m                 mv (file) (dest)"
                                echo 
                                echo "! commands...      execute a subshell"
                                echo 
                                echo "n                  skip to next file"
                                echo "$                  start over from the top"
                                echo "q                  quit"
				;;
			esac
		done
	done
done

