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"
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 [ -d $TEMPRUNDIR ]; 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)
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 $TEMPRUNDIR/output.$i; then
50 escaped=$(eval sed -e 's,\",\\\",g' $TEMPRUNDIR/output.$i)
51 output="${output:+$output
56 [ -n "${escaped:-}" ] || return
57 awesome-client <<-_eof
58 local naughty = require("naughty")
59 naughty.notify({ preset = naughty.config.presets.low,
60 title = "${1:-Output from mutt/$SELF}",
68 [ -d $TEMPRUNDIR ] || return
69 local stdout stderr anything
71 for i in stdout stderr; do
72 if [ -s "$TEMPRUNDIR/output.$i" ]; then
73 eval $i="'$TEMPRUNDIR/output.$i'"
79 notify "Output from mutt/$SELF" $stdout $stderr
83 python -c "import mimetypes; print(mimetypes.guess_extension('$1'))"
89 t=$(TMPDIR="$PWD" tempfile -s $(guess_extension "$MIMETYPE"))
93 t="$(echo ${1##*/} | sed -re 's![^[:alnum:],.@%^+=_-]!_!gi')"
94 ln "$1" "$t" 2>/dev/null || cp "$1" "$t"
99 MIMETYPE= FILENAME= VIEWER= DELAY=1
102 case "$state/$arg" in
105 (t/*) MIMETYPE="$arg"; state=;;
108 (f/*) FILENAME="$arg"; state=;;
111 (d/*) DELAY="$arg"; state=;;
114 (v/*) VIEWER="$arg"; state=;;
117 echo >&2 "E: Invalid argument: $i"
125 local filename; filename="$1"
126 if [ -z "$VIEWER" ]; then
127 [ -n "${2:-}" ] && filename="${2}:${1}"
128 run-mailcap "$filename" > $TEMPRUNDIR/output.stdout 2> $TEMPRUNDIR/output.stderr
130 $VIEWER "$filename" > $TEMPRUNDIR/output.stdout 2> $TEMPRUNDIR/output.stderr
136 # make a copy of the file, then launch a shell process in the background
137 # to divert to run-mailcap, after which the temporary directory gets
140 FILE="$(get_file "$FILENAME")"
142 ts=$(($(date +%s) + $DELAY))
143 launch_viewer "$FILE" "$MIMETYPE"
144 while [ $(date +%s) -lt $ts ]; do sleep $DELAY; done
147 trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15
150 # hack to stay around until the viewer has read the file: make a fifo and
151 # wait for the cat process to finish writing to it, which means that it
152 # must have been consumed on the other end.
154 FILE="$(get_file "$FILENAME")"
155 FIFO="fifo-${FILE##*/}"
157 cat "$FILE" > "$FIFO" &
158 # For some reason, we do have to write a tempfile and cannot seem to
159 # redirect stdin directly to the fifo, i.e. this does not work instead of
160 # the previous three lines:
162 launch_viewer "$FIFO" "$MIMETYPE"
167 # hack to stay around until the file hasn't been accessed for a few
168 # seconds, so that we can clean up. This is for cases when the FIFO method
169 # doesn't work, because e.g. Firefox randomly chooses it needs to read
172 FILE="$(get_file "$FILENAME")"
174 (launch_viewer "$FILE" "$MIMETYPE") &
176 while [ $(($(stat -c%X "$FILE") + $DELAY)) -gt $(date +%s) ]; do
179 echo Cleaning up $TMPDIR… > $TMPDIR/output.stderr
182 trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15