I do roughly the same, though I use a wrapper script that lets me choose an
inline (sixel) or external viewer. Sometimes I want to view the image while
walking mutt on to another task, and in that case the wrapper script
handles the lifecycle of the temporary file thus needed.

mailcap:
# -i or -e, or neither for a choice
image/*; mutt-view-image -i %s

mutt-view-image:
#!/bin/sh

case "$1" in
    -i) mode=inline; shift;;
    -e) mode=external; shift;;
    *)  : ;;
esac

if [ "$mode" = "" ]; then
    normal=$(stty -g)
    printf "Do you want to view (i)nline or (e)xternal? "
    trap "stty $normal" 1 2 3 15
    stty raw -echo

    c=$(dd if=/dev/stdin bs=1 count=1 2>/dev/null)
    stty $normal
    echo

    pause=false
    case "$c" in
        i*) mode=inline;;
        e*) mode=external;;
    esac
fi

if [ "$mode" = "inline" ]; then
    view="img2sixel %s 2>/dev/null"
    pause=true

elif [ "$mode" = "external" ]; then
    view="xopen %s; sleep 10"
fi

xopen () {
    # External open
    d=$(dirname "$1")
    f=$(basename "$1")
    fn="$d/async_$f"
    ln "$1" "$fn"
    at now + 5 minutes <<EOF
rm "$fn" >/dev/null 2>&1
EOF
    # This opens on Linux or MacOS
    (xdg-open "$fn" || open "$fn") 2>/dev/null
}

cmd=$(printf "$view" "$1")
eval $cmd
if $pause; then
    restore=$(stty -g)
    trap "stty $restore" 1 2 3 15
    echo
    echo "Press any key to continue..."
    stty raw -echo
    dd if=/dev/stdin bs=1 count=1 of=/dev/null
    stty $restore
fi

On Sun, Aug 1, 2021 at 3:58 PM Tavis Ormandy <tav...@gmail.com> wrote:

> On 2021-08-01, Patrick Shanahan wrote:
> > * Jude DaShiell <jdash...@panix.com> [07-31-21 23:34]:
> >> If memory serves, w3m can use av package if installed to allow it to
> view
> >> pictures.  I've only read about this never having been able to look at
> >> pictures.
> >> On Sat, 31 Jul 2021, D.J.J. Ring, Jr. wrote:
> >> > Has anyone succesfully configured mutt to give a roughly equivalent
> >> > view of html emails using w3m or other
> >> > browser in text console with direct-fb or other?
> > w3m is configuragle to display images, "auto_image=TRUE"
>
> Not exactly what was asked, but I use this mailcap to view image
> attachments:
>
> image/png; img2sixel -- %s | less -r; nametemplate=%s.png; needsterminal
>
> It uses the sixel support in xterm (or any other terminal that supports
> sixels) to display images in the terminal. I think you just need
> something like this in .Xresources to enable it in xterm:
>
> XTerm*decTerminalID: vt382
>
> Tavis.
>
> --
>  _o)            $ lynx lock.cmpxchg8b.com
>  /\\  _o)  _o)  $ finger tav...@sdf.org
> _\_V _( ) _( )  @taviso
>
>

Reply via email to