commit 45097d13b0ae1cd53a4349c1cb14a2fe8635b1be
parent ad015b5df06950c6391dc7eab9b558aee92250d6
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Thu, 18 Jun 2020 11:44:41 +0200
Make print script POSIX compatible
Diffstat:
1 file changed, 12 insertions(+), 16 deletions(-)
diff --git a/.config/mutt/muttprint-groff.sh b/.config/mutt/muttprint-groff.sh
@@ -1,17 +1,17 @@
#!/bin/sh
+set -e
PDIR="$HOME/tmp"
-mkdir -p "$PDIR" 2>/dev/null
-#rm -f "$PDIR"/mutt_*
+mkdir -p "$PDIR"
-infile="$(mktemp "$PDIR"/mutt_XXXXXXXX.txt)"
-tmpfile="$(mktemp "$PDIR"/mutt_XXXXXXXX.roff)"
-outfile="$(mktemp "$PDIR"/mutt_XXXXXXXX.pdf)"
+infile="$(mktemp "$PDIR"/mutt_XXXXXX)"
+tmpfile="$(mktemp "$PDIR"/mutt_XXXXXX)"
+outfile="$(mktemp "$PDIR"/mutt_XXXXXX).pdf"
-echo "infile = $infile"
-echo "tmpfile = $tmpfile"
-echo "outfile = $outfile"
+printf 'infile = %s\n' "$infile"
+printf 'tmpfile = %s\n' "$tmpfile"
+printf 'outfile = %s\n' "$outfile"
cat "${1:--}" > "$infile"
@@ -31,8 +31,7 @@ mail_cc="$(grep '^C[Cc]: ' "$infile" | tr ',' '\n')"
mail_subject="$(grep '^Subject: ' "$infile")"
{
- [ -n "$mail_subject" ] && printf ".TL\n%s\n" "$mail_subject" | sed 's/^Subject: //';
- [ -n "$mail_from" ] && printf ".AU\n%s\n" "$mail_from";
+ [ -n "$mail_subject" ] && printf ".TL\n%s\n" "$mail_subject" | sed 's/^Subject: //'; [ -n "$mail_from" ] && printf ".AU\n%s\n" "$mail_from";
[ -n "$mail_to" ] && printf ".AU\n%s\n" "$mail_to";
[ -n "$mail_cc" ] && printf ".AU\n%s\n" "$mail_cc";
[ -n "$mail_date" ] && printf ".AI\n%s\n" "$mail_date";
@@ -46,14 +45,11 @@ mail_subject="$(grep '^Subject: ' "$infile")"
sed 's/\(Fra\|Dato\|Til\|Emne\): /\n\1: /g' |\
sed 's/\(From\|Date\|To\|C[Cc]\|Subject\): /\n\1: /g' |\
sed 's/\(Links:\)/\n\1\n/g' |\
- sed 's/\(References:\)/\n\1\n/g' |\
- cat --squeeze-blank;
+ sed 's/\(References:\)/\n\1\n/g';
} > "$tmpfile"
echo "running groff $tmpfile $outfile"
preconv "$tmpfile" | groff -ms -T pdf > "$outfile"
-
-xdg-open "$outfile" &
-sleep 1
-rm "$infile" "$tmpfile" "$outfile"
+rm "$infile" "$tmpfile"
+xdg-open "$outfile"