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 TEMPDIR_SENTINEL=.tempdir
11 if [ -e $TEMPDIR_SENTINEL ]; then
12 local TEMPDIR; TEMPDIR="$PWD"
13 echo Cleaning up tempdir $TEMPDIR… >> output.stderr
20 trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15
22 trap cleanup 1 2 3 4 5 6 7 8 10 11 12 13 14 15
25 if [ -e $TEMPDIR_SENTINEL ]; then
29 if [ -z "${TMPDIR:-}" ]; then
32 for i in $LOGNAME volatile; do
33 if [ -d "${TMPDIR}/$i" ]; then
38 cd $(mktemp -dp "$TMPDIR" mutt.XXXXXXXXXX)
39 touch $TEMPDIR_SENTINEL
44 if [ -x "$(command -v awesome-client)" ]; then
45 local stdout stderr escaped output
48 for i in stdout stderr; do
49 if eval test -s output.$i; then
51 escaped=$(eval sed -e 's,\",\\\",g' output.$i)
52 output="${output:+$output
57 [ -n "${escaped:-}" ] || return
58 awesome-client <<-_eof
59 local naughty = require("naughty")
60 naughty.notify({ preset = naughty.config.presets.low,
61 title = "${1:-Output from mutt/$SELF}",
69 [ -e $TEMPDIR_SENTINEL ] || return
70 local stdout stderr anything
72 for i in stdout stderr; do
73 if [ -s "output.$i" ]; then
80 notify "Output from mutt/$SELF" $stdout $stderr
84 python -c "import mimetypes; print(mimetypes.guess_extension('$1'))"
90 t=$(TMPDIR="$PWD" tempfile -s $(guess_extension "$MIMETYPE"))
94 t="$(echo ${1##*/} | sed -re 's![^[:alnum:],.@%^+=_-]!_!gi')"
95 ln "$1" "$t" 2>/dev/null || cp "$1" "$t"
100 MIMETYPE= FILENAME= VIEWER= DELAY=1
103 case "$state/$arg" in
106 (t/*) MIMETYPE="$arg"; state=;;
109 (f/*) FILENAME="$arg"; state=;;
112 (d/*) DELAY="$arg"; state=;;
115 (v/*) VIEWER="$arg"; state=;;
118 echo >&2 "E: Invalid argument: $i"
126 local filename; filename="$1"
127 if [ -z "$VIEWER" ]; then
128 [ -n "${2:-}" ] && filename="${2}:${1}"
129 run-mailcap "$filename" > output.stdout 2> output.stderr
131 $VIEWER "$filename" > output.stdout 2> output.stderr
137 # make a copy of the file, then launch a shell process in the background
138 # to divert to run-mailcap, after which the temporary directory gets
141 FILE="$(get_file "$FILENAME")"
143 ts=$(($(date +%s) + $DELAY))
144 launch_viewer "$FILE" "$MIMETYPE"
145 while [ $(date +%s) -lt $ts ]; do sleep $DELAY; done
148 trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15
151 # hack to stay around until the viewer has read the file: make a fifo and
152 # wait for the cat process to finish writing to it, which means that it
153 # must have been consumed on the other end.
155 FILE="$(get_file "$FILENAME")"
156 FIFO="fifo-${FILE##*/}"
158 cat "$FILE" > "$FIFO" &
159 # For some reason, we do have to write a tempfile and cannot seem to
160 # redirect stdin directly to the fifo, i.e. this does not work instead of
161 # the previous three lines:
163 launch_viewer "$FIFO" "$MIMETYPE"
168 # hack to stay around until the file hasn't been accessed for a few
169 # seconds, so that we can clean up. This is for cases when the FIFO method
170 # doesn't work, because e.g. Firefox randomly chooses it needs to read
173 FILE="$(get_file "$FILENAME")"
175 (launch_viewer "$FILE" "$MIMETYPE") &
177 while [ $(($(stat -c%X "$FILE") + $DELAY)) -gt $(date +%s) ]; do
180 echo Cleaning up $TMPDIR… > $TMPDIR/output.stderr
183 trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15