AJ Kerrigan
Posted on March 23, 2023
Motivation
This is a bit cheeky and simplistic, but also reasonably accurate:
- Kitty has a graphics protocol that allows a terminal to render high-resolution images
- A number of tools support kitty's graphics protocol
- Tmux does not
- ...but I like tmux
Is this actually a problem?
One obvious solution here would be to... not use tmux. Kitty has its own support for windows/tabs/panes, and by all accounts it's quite full-featured. There are other terminals out there too. And hey, I'm all for trying out new tools. But some tools are ingrained enough in my fingers that I'm hesitant to discard them.
Time for a workaround
Since at least for the moment I'm not ready to give up tmux, what's the lowest friction way to still get kitty-quality images? The flow doesn't have to be pretty, just the image 😎. So far the way that feels smoothest to me combines:
Kitty remote control
I start a kitty session at login and keep it always a keyboard shortcut away. I've updated my startup command to listen on a unix socket:
kitty -o allow_remote_control=yes --listen-on unix:/tmp/kitty_remote_control
Kitty tabs
With my kitty session listening on a socket, I can run commands inside tmux that run in new kitty tabs outside of tmux:
kitty @ --to unix:/tmp/kitty_remote_control launch --type=tab --title='my new tab'
Timg
Kitty's graphics protocol page lists a number of tools that use it. While I haven't tried them all, I've become particularly fond of timg. It has some friendly options for things like upscaling and handling transparency/alpha channels. It also has the option to gracefully fall back from kitty-quality to half or quarter pixels in cases where a blocky image is OK.
Duct taping it together
With a kimg
script like this:
#!/bin/bash
set -euxo pipefail
FILE="$1"
shift
kitty @ --to unix:/tmp/kitty_remote_control launch --type=tab --title="$FILE" --no-response \
/bin/bash -c "timg -pk -B gray --title='%f (%wx%h)' $* '$(realpath $FILE)' && read -sn1"
I can use kimg <image file>
to:
- Open a new kitty tab outside tmux
- Run timg to display the image
- Wait for a keypress to close the kitty tab and return to my tmux home
Video demo
This short video shows the difference between opening an image in tmux directly vs. in a dedicated kitty tab:
Better options
If you've read this post and thought "wow that's pretty gross, why doesn't he just..." then great! First of all, thanks for reading. And second, please share your own suggestions.
Just keep in mind that if the suggestion is "abandon tmux" I'll be listening with my hands over my ears for now.
Posted on March 23, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.