All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
   3 #exec 2>> /tmp/bgrun.stderr
 
   9 TEMPRUNDIR=.tempdir-run.d
 
  11   if [ -d $TEMPRUNDIR ]; then
 
  12     local TEMPDIR; TEMPDIR="$PWD"
 
  17   trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15
 
  19 trap cleanup 1 2 3 4 5 6 7 8 10 11 12 13 14 15
 
  22   if [ -d $TEMPRUNDIR ]; then
 
  26     if [ -z "${TMPDIR:-}" ]; then
 
  29     for i in $LOGNAME volatile; do
 
  30       if [ -d "${TMPDIR}/$i" ]; then
 
  35     cd $(mktemp -dp "$TMPDIR" mutt.XXXXXXXXXX)
 
  41   if [ -x "$(command -v awesome-client)" ]; then
 
  42     local stdout stderr escaped output
 
  45     for i in stdout stderr; do
 
  46       if eval test -s $TEMPRUNDIR/output.$i; then
 
  47         escaped=$(eval sed -e 's,\",\\\",g' $TEMPRUNDIR/output.$i)
 
  48         output="${output:+$output
 
  53     [ -n "${escaped:-}" ] || return
 
  54     awesome-client <<-_eof
 
  55         local naughty = require("naughty")
 
  56         naughty.notify({ preset = naughty.config.presets.low,
 
  57                 title  = "${1:-Output from mutt/$SELF}",
 
  65   [ -d $TEMPRUNDIR ] || return
 
  66   local stdout stderr anything
 
  68   for i in stdout stderr; do
 
  69     if [ -s "$TEMPRUNDIR/output.$i" ]; then
 
  70       eval $i="'$TEMPRUNDIR/output.$i'"
 
  76   notify "Output from mutt/$SELF" $stdout $stderr
 
  80   python3 -c "import mimetypes; print(mimetypes.guess_extension('$1'))"
 
  86     t=$(mktemp -p "$PWD" tmp.XXXXXXXXXX$(guess_extension "$MIMETYPE"))
 
  90     t="$(echo -n ${1##*/} | sed -re 's![^[:alnum:],.@%^+=_-]!_!gi')"
 
  91     ln "$1" "$t" 2>/dev/null || cp "$1" "$t"
 
  96 MIMETYPE= FILENAME= VIEWER= DELAY=1
 
 102     (t/*) MIMETYPE="$arg"; state=;;
 
 105     (f/*) FILENAME="$arg"; state=;;
 
 108     (d/*) DELAY="$arg"; state=;;
 
 111     (v/*) VIEWER="$arg"; state=;;
 
 114       echo >&2 "E: Invalid argument: $i"
 
 122   local filename; filename="$1"
 
 123   if [ -z "$VIEWER" ]; then
 
 124     [ -n "${2:-}" ] && filename="${2}:${1}"
 
 125     run-mailcap "$filename" > $TEMPRUNDIR/output.stdout 2> $TEMPRUNDIR/output.stderr
 
 127     $VIEWER "$filename" > $TEMPRUNDIR/output.stdout 2> $TEMPRUNDIR/output.stderr
 
 133     # make a copy of the file, then launch a shell process in the background
 
 134     # to divert to run-mailcap, after which the temporary directory gets
 
 137     FILE="$(get_file "$FILENAME")"
 
 139       ts=$(($(date +%s) + $DELAY))
 
 140       launch_viewer "$FILE" "$MIMETYPE"
 
 141       while [ $(date +%s) -lt $ts ]; do sleep 1; done
 
 144     trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15
 
 147     # hack to stay around until the viewer has read the file: make a fifo and
 
 148     # wait for the cat process to finish writing to it, which means that it
 
 149     # must have been consumed on the other end.
 
 151     FILE="$(get_file "$FILENAME")"
 
 152     FIFO="fifo-${FILE##*/}"
 
 154     cat "$FILE" > "$FIFO" &
 
 155     # For some reason, we do have to write a tempfile and cannot seem to
 
 156     # redirect stdin directly to the fifo, i.e. this does not work instead of
 
 157     # the previous three lines:
 
 159     launch_viewer "$FIFO" "$MIMETYPE"
 
 164     # hack to stay around until the file hasn't been accessed for a few
 
 165     # seconds, so that we can clean up. This is for cases when the FIFO method
 
 166     # doesn't work, because e.g. Firefox randomly chooses it needs to read
 
 169     FILE="$(get_file "$FILENAME")"
 
 171     (launch_viewer "$FILE" "$MIMETYPE") &
 
 173       while [ $(($(stat -c%X "$FILE") + $DELAY)) -gt $(date +%s) ]; do
 
 178     trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15