
imgcat and PS1
It’s been at the back of my mind that I could probably use some of the more advanced features of iTerm2, rather than just using it as a Visor TotalTerminal replacement (where pressing ctrl-space
toggles a full-screen terminal and back again).
But after seeing this great Twitter thread: 💡FAQ about displaying stuff in a terminal from Kate I thought I’d check whether iTerm2 can display images. Ace, it can! There are two helpers; one for cat
-ing images imgcat and imgls for ls
-ing a folder with thumbnails.
Kate uses kitty for her terminal, which in turn uses libsixel and the Sixel graphics format originally designed for terminals and dot-matrix printers.
Another nice trick in the thread is to change your terminal prompt to red for a non-zero exit status. I’m a bash stalwart, so here’s how to do that:
export PS1="\$([ \$? -gt 0 ] && printf '\[\033[31m\]'; printf '$ \[\033[0m\]')"
It checks the exit code [ $? -gt 0 ]
(you need the backslashes in the PS1
line above so $
is correctly interpolated) and if the result is non-zero, print the escape sequence for red. Then print the prompt $
followed by the escape sequence to set text back to normal (in case we’ve printed red).
I tend to rely on gnu screen to handle displaying the current folder, git branch, current screen window etc, using this .screenrc
madness that I’ve cribbed from across the internet:
hardstatus string '%{= #ff0000}%{= #ffffff}%?%-Lw%?%{#ff0000}(%{#ffffff}%n%f%t%?(%u)%?%{#ff0000})%{#ffffff}%?%+Lw%?%?%= %{#00ff00}'
# https://www.gnu.org/software/screen/manual/html_node/Backtick.html
backtick 1 1 1 cat $HOME/.pwd # %1 in caption
backtick 2 1 1 $HOME/bin/cwb # %2 in caption
caption always "%1` (%2`)"
Which gives me a nice status line:
But having that red prompt on errors is a nice touch:
All links, in order of mention:
- iTerm2: https://iterm2.com/
- Visor: https://visor.binaryage.com/
- TotalTerminal: https://totalterminal.binaryage.com/
- 💡FAQ about displaying stuff in a terminal: https://twitter.com/thingskatedid/status/1316074032379248640
- Kate: https://twitter.com/thingskatedid
- whether iTerm2 can display images: https://iterm2.com/documentation-images.html
- imgcat: https://iterm2.com/utilities/imgcat
- imgls: https://iterm2.com/utilities/imgls
- kitty: https://sw.kovidgoyal.net/kitty/
- libsixel: https://saitoha.github.io/libsixel/
- Sixel graphics format: https://en.wikipedia.org/wiki/Sixel
- change your terminal prompt to red for a non-zero exit status: https://twitter.com/thingskatedid/status/1316081732467081217
- gnu screen: https://www.gnu.org/software/screen/
Recent posts:
- Patch for aarch64 (aka arm64) openssl 1.0.2 'relocation R_AARCH64_PREL64 against symbol OPENSSL_armcap_P error'
- TIL: the `NO_COLOR` informal standard to suppress ANSI colour escape codes
- Copy the contents of a branch into an existing git branch without merging
- Adding search to a static Jekyll site using pagefind
- asdf, python and automatically enabling virtual envs