Cleaned up error checking for temporary files, removed redundant check.

Fixed status check for copy and editor launch.
This commit is contained in:
Jesse 2024-05-02 09:33:09 -03:00
parent 2f1843bb41
commit 7c3981ce28
2 changed files with 8 additions and 11 deletions

View file

@ -1,4 +1,4 @@
Copyright (c) 2017, Jesse Smith
Copyright (c) 2017-2024, Jesse Smith
All rights reserved.
Redistribution and use in source and binary forms, with or without

View file

@ -31,12 +31,6 @@ then
fi
temp_file=$(mktemp --tmpdir doasedit.XXXXXXXX)
if [ ! $? ]
then
echo "Could not create temporary file."
exit 4
fi
if [ ! -r "$temp_file" ]
then
echo "Was unable to create temporary file."
@ -45,7 +39,8 @@ fi
mydir=$(dirname -- "$1")
cp "$mydir/$1" "$temp_file"
if [ ! $? ]
status=$?
if [ $status -ne 0 ]
then
echo "Unable to copy file $1"
exit 5
@ -55,12 +50,14 @@ fi
# $EDITOR should be a line editor functional without advanced terminal features.
# $VISUAL is a more advanced editor such as vi.
"${VISUAL:-vi}" "$temp_file"
if [ ! $? ]
status=$?
if [ $status -ne 0 ]
then
echo "Could not run visual editor $VISUAL"
"${EDITOR:-ex}" "$temp_file"
if [ ! $? ]
status=$?
if [ $status -ne 0 ]
then
echo "Could not run visual editor $VISUAL"
echo "Could not run editor $EDITOR"
echo "Please make sure the VISUAL and/or EDITOR variables are set."
rm -f "$temp_file"