BSD 4_3_Net_2 development
[unix-history] / usr / src / contrib / isode / quipu / dish / editentry
#!/bin/sh
#
if [ $# != "1" ]; then
echo usage: editentry filename
exit 1
fi
F=T
while test -z "$EDITOR"
do
if [ $F = "T" ]; then
echo 'You do not have the shell variable $EDITOR set.'
F=F
fi
echo ''
echo -n 'Enter the name of an editor: '
read EDITOR rubbish
if [ ! -x "$EDITOR" ]; then
IFSS="$IFS"
IFS=: F="$EDITOR"
EDITOR=
for D in $PATH; do
if [ -x "$D/$F" ]; then
EDITOR="$D/$F"
break
fi
done
if [ -z "$EDITOR" ]; then
echo "$F not found, please try again..."
fi
IFS="$IFSS"
fi
done
cp $1 $1.tmp
E=T
while true
do
if [ $E = "T" ]; then
if $EDITOR $1; then
if cmp -s $1 $1.tmp; then
mess="No changes to draft entry - shall I continue? "
else
mess="Are you sure you want to make these changes? "
fi
else
echo 'Edit aborted...'
rm -f $1.tmp
exit 1
fi
fi
echo -n "$mess"
read YN rubbish
case "$YN" in
y|yes|Y|YES)
rm -f $1.tmp
exit 0
;;
n|no|N|NO)
mv $1.tmp $1
exit 1
;;
e|edit|E|EDIT)
cp $1 $1.tmp
if [ ! -z "$rubbish" ]
then
EDITOR="$rubbish"
fi
E=T
;;
u|undo|U|UNDO)
cp $1.tmp $1
E=T
;;
*)
case "$YN" in
\?|""|h|help|H|HELP)
mess='Options are:'
;;
*)
mess="\"$YN\" not understood -- use one of:"
;;
esac
echo "$mess"
echo ' yes - to commit'
echo ' no - to abort'
echo ' edit - to continue editing'
echo ' undo - to undo last edit and edit some more'
mess='Try again: '
E=F
;;
esac
done