
lsix: ls for images - bb88
https://github.com/hackerb9/lsix
======
isomorphic
Aside: Although iTerm2 (on macOS) doesn't appear to work with this, iTerm2
actually supports full-color inline images, and has an "imgls" script which
does something similar. (There's also "imgcat".)

[https://www.iterm2.com/documentation-
images.html](https://www.iterm2.com/documentation-images.html)

~~~
fouc
>iTerm2 extends the xterm protocol with a set of proprietary escape sequences.

I wonder if any other terminal uses the same escape sequences. If not, why
not?

~~~
laumars
It’s worse than that, there’s other shells that support their own ANSI escape
sequence for transferring base64 encoded images: kitty (not to be confused
with KiTTY - the PuTTY fork) and Terminology (of enlightenment DE) each have
their own “standard” and they differ from iTerm2’s. They all have their own
CLI tools too.

Then there is sixel - which solved a problem back when TTYs were VDUs but
aren’t really suitable for a modern era where it’s all terminal emulators
running on (U)HD displays. I don’t think sixel support is all that widespread
though but happy to be corrected there.

What we really need is one CLI tool to rule them all. One tool that will
detect the shell you’re using and default to the best escape sequence for that
shell; falling back to ASCII art when all else fails.

This is something I’ve been actively working on in some of my spare time but
it’s not ready for public consumption, yet....

~~~
boomlinde
Pedantry: Those are terminal emulators, not shells.

~~~
laumars
Yeah I did say “terminal emulators” else where in that comment. Not really
sure why I said “shells” in the first line. Must have been having a senior
moment....

------
tedunangst
I would be wary about feeding untrusted inputs to imagemagick. Running this in
your downloads directory could be surprising.

~~~
jstewartmobile
" _untrusted inputs to imagemagick_ ", stickied to the top, with a big yellow
exclamation mark beside it

------
userbinator
_You can also specify filenames and, of course, use shell wild cards_

 _However, some may be slow to render (like PDF), so lsix doesn 't show them
unless you ask specifically._

Regardless of the justification, I don't think creating such extra
exception/edge-case behaviours are ever a good idea in a commandline tool like
this. The equivalent in regular ls would be something like not showing more
than X files "unless you ask specifically" \--- which would just create more
confusion than anything. As someone who has used the commandline for many
years, one property which needs to be present for good usability is
_consistency_. Having a bunch of edge-cases and special behaviours makes a
tool hard to use for anything but the most extremely basic of operations.

~~~
ObsoleteNerd
Are PDFs really expected to preview in an image viewer though? I don't really
think of them as images, so I see the flag to preview them as more of an
"extra feature", which is exactly what flags are for.

If it didn't preview GIFs without a flag, or PNGs, then your point would
absolutely stand.

~~~
kijin
Exactly. PDFs are documents, not images. Just because ImageMagick can convert
PDFs into images doesn't make them images.

Every image viewer on Earth excludes DOCs and PPTs by default, but nobody
complains about that.

~~~
TeMPOraL
I recall at least one vector drawing program offering PDF as target, and this
being expected in some print shops, so yes, in some cases, PDFs can be images.

PDF is a weird format with a bunch of disjoint use cases.

~~~
a1369209993
GIMP offers ASCII art as a target, and that's expected by line
printers/teletypewriters; does that mean TXTs can be images?

~~~
jchw
Yeah, you just described how too. KDE used to thumbnail txt files with a
portion of their actual text.

~~~
bmn__
Still does.

Dolphin → Settings → Configure Dolphin… → General → Previews

~~~
jchw
I see; I mostly used KDE in the 3.x days, back when Konqueror was the file
manager and Webkit was still a fairly young KHTML fork.

~~~
bmn__
Konqueror and Dolphin use the same kpart under the hood for directory display.

Konqueror → Settings → Configure Konqueror… → File Management → General →
Previews leads to the same configuration dialog.

------
snazz
Semi-related fun fact: if you have iimage-mode turned on in Emacs (it might be
the default on recent versions?), you can just cat images in eshell and have
them show up just like this app. Unfortunately it doesn't do sixel graphics in
a terminal yet.

~~~
komali2
Dude this is so off topic but I just gotta know what the madness that your hn
"about" section is

~~~
snazz
[https://lingojam.com/WeirdTextGenerator](https://lingojam.com/WeirdTextGenerator)

------
makecheck
I verified that "lsix" works with MacTerm (my project), which implements
Sixels and incidentally also implements the iTerm2 sequences used by "imgls".
Rendered areas can be selected and saved or dragged as whole pictures, which
may be useful for remote images.

------
kuhhk
Wouldn’t this be more like “cat” than “ls”? List is for listing files, cat is
for outputting the files, and this appears to output the image...

~~~
danso
Only if the output is the image’s exact contents. This seems to output image
data and text.

------
amyjess
Well, I learned three things today:

\- Sixels exist

\- Konsole doesn't support them.

\- I don't have xterm installed.

After installing xterm and trying this out, I'm pretty impressed. Though not
impressed enough to stop using Konsole.

------
merlincorey
It's pretty incredible that this is a bash script that outputs sixel graphics,
and it in no way makes use of libsixel[0].

[0] [https://github.com/saitoha/libsixel](https://github.com/saitoha/libsixel)

~~~
theoh
It uses various Imagemagick tools (Imagemagick supports sixel).

Nobody manipulates binary files/pixel data in bash, do they?

~~~
aasasd
> nobody

That's a strong word you have there.

~~~
floatingatoll
They have a point - I can’t find any traces of a shell library implementing
image parsing without calling out to a third-party tool written in not-shell.

You also have a point - I’m seriously debating if I can write one in an
evening solely to say that one now exists. (I lost the debate with myself,
sadly.)

EDIT: I mean “source language bash”, not “target language bash”, my emscripten
friends.

~~~
theoh
There are problems with the manipulation of binary data in bash, as discussed
here: [https://unix.stackexchange.com/questions/278639/how-can-i-
wo...](https://unix.stackexchange.com/questions/278639/how-can-i-work-with-
binary-in-bash-to-copy-bytes-verbatim-without-any-conversio)

In particular, the value 0 can't be stored in a bash variable, which almost
completely rules out the possibility of byte-by-byte processing of general
binary data. It's probably possible with absurd hacks.

Quite apart from that, error handling in bash is an awkward chore which few
scripts get right. It's a very unappealing language for writing anything more
than a five-line script. [https://www.davidpashley.com/articles/writing-
robust-shell-s...](https://www.davidpashley.com/articles/writing-robust-shell-
scripts/)

~~~
floatingatoll
If you read a byte without EOF and have a variable length of 0 afterwards, you
read a NUL.

------
jopsen
How many terminal emulators can handle sixel? (vt340)

Does anyone have a list?

~~~
amasad
As far as I know it's just xterm on desktop. It's fascinating that we have
this standard that allows us to build programming environments like notebooks
-- without resorting to layering hacks on hacks to make it work on web --
practically crossplatform yet we don't make use of it.

At repl.it we've been toying around with adding sixel support for xterm.js and
we have a prototype up and people in our community are already building things
on it.

Here are a few examples:

\- gnuplot:
[https://gnuplot.basicer.repl.run/rob](https://gnuplot.basicer.repl.run/rob)

\- gif in terminal (python): [https://repl.it/talk/share/SPINNING-GLOBE-GIF-
WITH-SIXEL-NEW...](https://repl.it/talk/share/SPINNING-GLOBE-GIF-WITH-SIXEL-
NEW/9139)

\- connect 4 game (ruby): [https://repl.it/talk/share/Connect-4-20-with-
better-graphics...](https://repl.it/talk/share/Connect-4-20-with-better-
graphics-and-more-effects/9338)

~~~
jopsen
It's also facinating that programs that generate text output do so in a format
that's well over 40 years old.

What if our CLI programs could output HTML or JSON depending on whether they
are piped or printed.

Both standards are not good for this, but is VT100 really that great?

~~~
Wowfunhappy
Most terminals use unicode, not ascii, right? Unicode is much younger than 40.

~~~
nwhm
Unicode isn't an encoding, but most terminals use UTF-8 (check your LANG
environment variable), of which ascii is a subset

------
euske
Cooool! Is there any way to get this work with tmux? Currently it seems it's
filtering Sixel escape sequences. On a raw xterm it's fine.

~~~
anowlcalledjosh
Probably not, see
[https://github.com/tmux/tmux/issues/44](https://github.com/tmux/tmux/issues/44)
(tldr: maintainer says no).

There's a fork that purports to add support, but it's not been updated for a
while: [https://github.com/yatli/tmux-sixel](https://github.com/yatli/tmux-
sixel)

~~~
dotancohen
Note that it is the tmux maintainer, not the libsixel maintainer, who is
saying no. He won't even add support if someone else provides the patch,
unless the patch is small. Why? Because:

> "I am not interested in graphics in the terminal and there are few practical
> uses for them anyway."

Really? I wonder how the *nix environment would look like today if the tools
(gnu, et al) only worked with the workflows that their original creators
envisioned. In fact, just recently I had to SSH into a remote server and find
a particular image. The filenames are random strings, and the timestamps were
useless as the files were recently copied from an archive drive without the
`-a` flag. Having image support in the terminal would have saved me enough
time to pick up my little one from kindergarten myself instead of having to
send someone else to pick him up for me.

------
wazoox
Doesn't seem to work neither on Ubuntu nor Slackware Linux for me... It only
outputs some error messages about "missing delegates for this format" and
other errors (ImageMagick 6.9.7.4 and bash 4.4.18 in one case, and IM 6.9.4
and bash 4.3.48 in the other; same kind of errors).

------
walrus01
Also fun with text, you can use aalib as an output renderer with VLC to watch
any video as ASCII art. For example 'the matrix' I know Kung Fu scene.

[https://en.wikipedia.org/wiki/AAlib](https://en.wikipedia.org/wiki/AAlib)

------
lbj
How does the tech work? You have something like a 80x50 display and he's
emitting 128x128px on that?

~~~
emmanueloga_
By now a lot of ppl have commented on the tech (sixel) but it really annoys me
when projects don't explain in simple terms the overall workings in the
readme:

"lsix is a shell script that uses ImageMagick convert tool to list images on a
shell screen on terminals that support the Sixel format"

There, was that so hard?!? :-(

EDIT: oops, it does mention it, everywhere actually. 1) need to pay more
attention but 2) I was just venting because of so many other repos I have to
spelunk to have answers for when a few words in the readme would do :-)

------
djsumdog
Hmm, it doesn't look like xfce4-terminal supports sixel bitmaps.

------
fake-name
Works in cygwin/MiniTTY. Awesome!

OTOH, when using screen, it completely poops itself. Sadface.

Also, wow, it's slow.

~~~
jandrese
Despite being old as the hills and seemingly unchanged over the years
ImageMagick still manages to be slow. It is a mystery how the developers
managed this feat.

It's a shame that netpbm seems to be mostly dead, it always worked much better
for the kind of tasks that most people use ImageMagick for, at least for me.

------
EGreg
Does this work in MacOS terminal and SSH?

~~~
pmarreck
[https://www.macterm.net/](https://www.macterm.net/) seems to support sixels

EDIT: And despite the option in there being on, I can't seem to get it to
output graphics instead of binary garbage when I use the "lsix" bash script.

~~~
makecheck
I will try to help if I can. It does work for me.

The script seems to depend on ImageMagick "convert" for most of its work; when
I run "convert -version" I see "ImageMagick 7.0.6-0 Q16 x86_64 2017-06-12", is
this newer than the version you are using?

~~~
pmarreck
I got it to work either by picking a different terminal type or restarting the
app after enabling the option!

------
koshak
Every time I see the word beginning from sumbol "l" I can’t tell whether it is
"l" or "I"

The only font designers who care about clear distinction of symbols are those
who create fonts for coders

Simple clarity test:

Il10O

All 5 chars should have clear distinction. Otherwise the font is shit.

~~~
y4mi
often, you can clearly distinguish them from each other... but still don't
know which is which.

though i admit, that its become pretty normal for the I to be smaller than the
l and the O to be rounder than the 0.

I'd prefer that to be even clearer. I.e. a point in the Zero or rounding the
ends of the small L

------
kristopolous
Size would be a nice option

------
utopcell
Beautiful! (-:

------
quickthrower2
Nice, but by the time you want to do this, why not use a GUI file explorer
with image thumbnails

~~~
ubercow13
Faster over SSH maybe? Where the thumbnail can be generated remotely

~~~
quickthrower2
Nice point I hadn’t thought of that scenario. Thanks.

