Listing 2: lvi--A simple locking vi script
#
# lvi: Simple locking vi script
#
contprompt=""
for file in $*; do
#
# We'll prompt to continue if last file processed
# was locked.
#
if [ "$contprompt" ]; then
echo "Continue with next file ($file)? \c" >&2
read ans junk
ans=`echo "$ans" | tr "[a-z]" "[A-Z]"`
case "$ans" in
Y|YES)
: continue
;;
*)
exit $rc
;;
esac
fi
#
# Check for lock, do not wait on it.
#
rlock -q $file
rc=$?
if [ $rc != 0 ]; then
#
# File is locked, prompt if more files
# available.
#
echo "lvi: File $file is locked." >&2
contprompt=True
else
#
# File is not locked, edit using vi.
#
contprompt=""
vi $file
fi
done
exit $rc
|