summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdoasedit13
-rw-r--r--doasedit.845
2 files changed, 48 insertions, 10 deletions
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.
diff --git a/doasedit.8 b/doasedit.8
index d1c99f5..6e07de8 100644
--- a/doasedit.8
+++ b/doasedit.8
@@ -16,7 +16,7 @@
.\" TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
.\" PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd November 14, 2022
+.Dd Match 25, 2026
.Dt DOASEDIT 8
.Os
.Sh NAME
@@ -46,18 +46,51 @@ is tried instead.
If both environment variables are not set then
.Xr vi(1)
is used as a fallback.
+.Pp
+By default
+.Nm
+will create a temporary file in
+.Ev TMPDIR .
+If
+.Ev TMPDIR
+is not set it will fallback to using
+.Pa /tmp .
+.Pp
+When editing a file the
+.Ev DOASEDIT_EDITING
+environment variable will be set to the absolute path of
+.Ar file .
+Editors can use this to ensure that filetype-specific configurations are
+properly applied.
.Sh EXIT STATUS
.Ex -std
.Sh ENVIRONMENT
.Bl -tag -width Ds
-.It Ev VISUAL
-The editor to use to edit the target text file.
-If the VISUAL variable is not set, then EDTIOR is used as a fallback.
+.It Ev DOASEDIT_EDITING
+The absolute path to the root-protected file currently being edited.
.It Ev EDITOR
-The editor to use to edit the target text file if VISUAL is not set.
-If the EDITOR variable is not set, then the command
+The editor to use to edit the target text file if
+.Ev VISUAL
+is not set.
+If the
+.Ev EDITOR
+variable is not set, then the command
.Xr vi 1
is used.
+.It Ev TMPDIR
+The directory in which to create the temporary file copy to edit.
+If the
+.Ev TMPDIR
+variable is not set,
+.Pa /tmp
+will be used as a fallback.
+.It Ev VISUAL
+The editor to use to edit the target text file.
+If the
+.Ev VISUAL
+variable is not set, then
+.Ev EDTIOR
+is used as a fallback.
.El
.Sh SEE ALSO
.Xr doas 1 ,