
: TNIX/UNIX version - 06FEB1984
: Keyshell Version Number 2

: remove - a shell command file called by setksh to remove the current
: or saved Keyshell configuration

cat <<!!

Do you wish to:

	1)	Remove the current configuration

	2)	Remove a saved configuration

	3)	Return to main menu

Enter your choice: 
!!

looptest=0
while test $looptest 
do
	read INPUT
	case $INPUT in
	1)
		if test -f $HOME/.setKSH
		then
			rm -f -r $HOME/.setKSH $HOME/.ksh
			echo "...Current ColorKey+ configuration removed..."
			exit
		else
			echo "Can't remove: no current configuration"
			exit 1
		fi
		;;
	2)
		saved=
		if test -d $HOME/.saveksh	
		then
			echo
			echo "Saved ColorKey+ Configurations:"
			echo
			ls -1 $HOME/.saveksh
			saved=0
		else 
			echo "Can't remove: No saved ColorKey+ configurations."; 
			exit1
		fi

		if test $saved			
		then				
			looptest2=0
			while test $looptest2 	
			do
				echo
				echo -n "Enter the name(s) to remove (<CR> returns to main menu): "
				read newname
				if test -z "$newname"
				then			
					echo ...configuration not removed...
					exit 1
				else			
					for i in $newname
					do
					  if test -d $HOME/.saveksh/$i
					  then
						  rm -f -r $HOME/.saveksh/$i
						  echo ... $i removed ...
					  else		
						  echo Can\'t remove: $i not found
					  fi
					done
: remove $HOME/.saveksh if empty
					found=
					for i in `ls -a $HOME/.saveksh`
					do
						if test "$i" != '.' -a "$i" != '..'
						then
							found=1
							break
						fi	
					done
					
					if test $found
					then
						:
					else
						rmdir $HOME/.saveksh
					fi
					exit
				fi
			done
		fi
		;;
	3)
		exit 1
		;;
	*)	echo "Invalid input: Please enter a number in the range [1-3]"
		echo
		echo -n "Enter your choice: "
		;;
	esac
done
