Open chapmanjacobd opened 3 weeks ago
very cool! this must use sixel graphics? I never developed much skill with fish but it looks like this is cb with shell image support. my current thinking is that I kind of like how simple and dumb cb is but what I like about yours is that it adds some extra value over tools like xclip. I'll leave this issue open to think about it some more but, regardless, this is a very neat idea!
Yeah it's not fully compatible with cb
and it's far from cross-platform.
Sixel adoption is pretty good but not quite universal: https://www.arewesixelyet.com/ It looks like kitty uses its own graphics protocol
But I agree, the idea likely has potential... The key insight for me was this:
if test -t 1
bat $file
else
cat $file
If stdout is connected to a terminal we can use a different program to preview it. Otherwise, we are connected to a pipe which could be a second cb
instance, etc so we send the raw data.
(The above example is useful for showing why you might want a different program for text previewing even though it is not technically needed because bat
also checks stdout is a tty and then behaves like cat
. But image printing programs like lsix
or kitten icat
have no reason to pipe the original data forward and so they don't check stdout--they output the image data the same way such that it could be re-printed but no longer png format so it can't be re-sent to ImageMagick...)
Actually, ImageMagick supports decoding/encoding Sixel: https://github.com/ImageMagick/ImageMagick/blob/master/coders/sixel.c so that might be an interesting exploration point. Maybe checking stdout is not really needed
I made a little
cb
inspired thing:Thankfully at least ImageMagick supports stdin/stdout: