doasedit: fallback to EDITOR if VISUAL fails

This commit is contained in:
cerulis64 2021-10-06 10:04:33 -07:00
parent 66519077d6
commit 6e07ac9a40
No known key found for this signature in database
GPG key ID: 9EDF9B33AB1DA3A2
2 changed files with 15 additions and 6 deletions

View file

@ -44,13 +44,21 @@ then
exit 5
fi
"${EDITOR:-vi}" "$temp_file"
# If $VISUAL fails, run $EDITOR.
# $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 [ ! $? ]
then
echo "Could not run editor $EDITOR"
echo "Please make sure EDITOR variable is set."
rm -f "$temp_file"
exit 6
"${EDITOR:-ex}" "$temp_file"
if [ ! $? ]
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"
exit 6
fi
fi
# Check to see if the file has been changed.

View file

@ -36,7 +36,8 @@ to run their text editor as the super user.
.Pp
The doasedit utility accepts one argument, the file to
be edited. The text editor used during the editing process
is set using the EDITOR environment variable.
is set using the VISUAL environment variable. If VISUAL fails
to run, EDITOR is tried instead.
.El
.Sh EXIT STATUS
.Ex -std