From bc6a09475dd947bfc8a0fb4dbb15355f07eaba97 Mon Sep 17 00:00:00 2001
From: NRK <nrk@disroot.org>
Date: Sun, 19 Feb 2023 21:14:53 +0600
Subject: [PATCH] nmv: ensure the tmpfile is cleaned up in all cases

currently, there's a couple exit paths where the tmpfile doesn't get
cleaned up.
---
 plugins/.nmv | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/plugins/.nmv b/plugins/.nmv
index bbbdafe7..eaebda6c 100755
--- a/plugins/.nmv
+++ b/plugins/.nmv
@@ -37,8 +37,6 @@ esac
 
 exit_status=0
 
-dst_file=$(mktemp "$TMPDIR/.nnnXXXXXX")
-
 if nnn_use_selection "Rename"; then
 	# shellcheck disable=SC2154
 	arr=$(tr '\0' '\n' < "$selection")
@@ -65,6 +63,9 @@ fi
 lines=$(printf "%s\n" "$arr" | wc -l)
 width=${#lines}
 
+dst_file=$(mktemp "$TMPDIR/.nnnXXXXXX")
+trap 'rm -f "$dst_file"' EXIT
+
 printf "%s" "$arr" | awk '{printf("%'"${width}"'d %s\n", NR, $0)}' > "$dst_file"
 
 items=("~")
@@ -170,5 +171,4 @@ for item in "${items[@]}"; do
 	$RM_UTIL "$item"
 done
 
-rm "$dst_file"
 exit $exit_status
-- 
2.51.0