From 2e31cd732213c3d974089cad8e88ab2bb3ccf371 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Tue, 14 Aug 2018 11:16:26 +1200 Subject: [PATCH] improved tempfile handling --- .mutt/bgrun | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.mutt/bgrun b/.mutt/bgrun index e0bcd20..260925c 100755 --- a/.mutt/bgrun +++ b/.mutt/bgrun @@ -9,10 +9,10 @@ elif [ -d "${TMPDIR}/volatile" ]; then fi export TMPDIR TMPDIR=$(mktemp -dp "$TMPDIR" mutt.XXXXXXXXXX) -trap "rm -rf '$TMPDIR'" 1 2 3 4 5 6 7 8 10 11 12 13 14 15 +cleanup() { cd / && rm -rf "$TMPDIR"; } +trap cleanup 1 2 3 4 5 6 7 8 10 11 12 13 14 15 -BASENAME="${1##*/}" -TEMPFILE="${TMPDIR}/${BASENAME}" +cd "$TMPDIR" notify() { if [ -x "$(command -v awesome-client)" ]; then @@ -38,11 +38,11 @@ case "$SELF" in MIMETYPE="$2" ( run-mailcap --action=view "$MIMETYPE":"$TEMPFILE" - rm -rf "$TMPDIR" if [ -s "$TMPDIR/output.stdout" ] || [ -s "$TMPDIR/output.stderr" ]; then notify $TMPDIR/output.stdout $TMPDIR/output.stderr \ "Output from mutt/$SELF on $BASENAME" fi + cleanup ) & trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15 ;; @@ -55,6 +55,6 @@ case "$SELF" in cat "$INPUTFILE" > $TEMPFILE & sensible-browser "$TEMPFILE" > $TMPDIR/output.stdout 2> $TMPDIR/output.stderr wait + cleanup ;; esac - -- 2.39.5