From ccf690c0b78f13660e60625f698178638c7d2639 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 29 Mar 2026 23:20:52 +0200 Subject: Add the DOASEDIT_EDITING environment variable --- doasedit | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'doasedit') diff --git a/doasedit b/doasedit index b0741ce..3d905dd 100755 --- a/doasedit +++ b/doasedit @@ -32,6 +32,11 @@ get_intr() { }' } +get_abspath() ( + cd "$(dirname "$1")" + echo "$(pwd)/$(basename "$1")" +) + PROG=${0##*/} [ $# -ne 1 ] && { @@ -43,17 +48,17 @@ PROG=${0##*/} [ -L "$1" ] && die 2 "$1: File is a symbolic link, refusing to edit." [ ! -r "$1" ] && die 3 "$1: File cannot be read by the current user." -tmp=$(mktemp --tmpdir doasedit.XXXXXXXX --suffix="$(echo "$1" | tr '/' '-')") || - die 4 "Could not create temporary file." +tmp="$(mktemp -p doasedit.XXXXXXXX)" || die 4 "Could not create temporary file." trap "rm -f $tmp" EXIT HUP INT TERM cp "$1" "$tmp" || die 5 "$1: Unable to copy file." -"${VISUAL:-${EDITOR:-vi}}" "$tmp" || { +abspath="$(get_abspath "$1")" +DOASEDIT_EDITING="$abspath" "${VISUAL:-${EDITOR:-vi}}" "$tmp" || { warn "Could not run visual editor '$VISUAL' or editor '$EDITOR'." die 6 "Make sure the VISUAL and/or EDITOR variables are set." } -cmp -s "$1" "$tmp" && \ +cmp -s "$1" "$tmp" && die 0 "File unchanged. Not writing back to original location." # At this point the file has been changed. Make sure it still exists. -- cgit v1.2.3