Thank you for this, and my apologies for top-posting. I have w3m installed but 
it does not have img2sixel in it (I use Fedora). Could I use w3m (on something 
else) instead in the code that you have provided?

Thanks!







On Friday, December 4, 2020, 3:51:03 PM CST, David Champion <d...@c13.us> 
wrote: 





* On 03 Dec 2020, Globe Trotter via Mutt-users wrote: 
> Hi,
> 
> If I use w3m -o ext_image_viewer=0 test.png, I can get the file test.png 
> inside xterm.
> 
> I wanted to do the same on my mutt window (inside xterm). How do I do this?
> 
> I tried putting:
> 
> image/*;w3m -o ext_imageviewer=0 %s; copious output
> 
> However this does not work and gives me the options of w3m in the mutt 
> window. How can I use this?
> 
> TIA!

This is not an answer to your exact question, but here's how I view
images in mutt. Note that by default it prompts me for inline or
external viewing, but I can insert -i or -e in the mailcap entry to
always use one or the other.  The part that's most related to your
question is that I use img2sixel for the rendering. img2sixel comes with
libsixel.  IIRC w3m uses libsixel internally, so img2sixel is a quicker
path to success using the same underlying tooling if your input is
definitely an image.

Sixel is a technique developed by DEC to embed color bitmapped image
data in a VT320/VT400 device control string (DCS) stream of six-bit
character data. It's probably the most widely supported technique today
for inline images in terminal emulators, although some terminals such as
iTerm support their own bitmap streaming formats as well.

Unfortunately I haven't found any such technique that works well over
tmux or screen.  There's a thread about this topic on the tmux github
issues page, concluding that it's not worth the developers' time to
support.


.mailcap:
image/*; mutt-view-image %s


.muttrc:
macro index,pager \Cv 
'<view-attachments><search>image/<enter><view-attach><exit>' 'View image 
attachment'


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 () {
    set -x
    # 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


exit

-- 
David Champion • d...@c13.us

Reply via email to