Switching from iTerm2 to Kitty
I’ve been a long-time, hardcore user of iTerm2 on Mac. One of the big reasons I love using my Mac everyday is because of iTerm2’s plethora of features. However, I’ve begun to feel like it has become sluggish and bloated. A lot of features I don’t even use and some I try to but they don’t work consistently. In the cases when I need to use Linux, what do I even use? I can’t stand Gnome Terminal. And my recent fascination with ligatures in fonts like Fira Code has left me wanting more typography support and speed.
In steps Kitty.
After looking through various terminal options for Mac (and also keeping in mind what is cross-platform) Kitty seemed like the perfect replacement. Here’s how I switched from iTerm2 with no looking back. I hope it helps you if you run into any of the issues or feature “requirements” that I did!
Configuration
The first thing about Kitty is that it has all of its configuration in a text file. This makes backup and restore on par with other dot files. And it obviously means configuring and testing the options isn’t as hand-holdy but that’s OK.
The par features I wanted:
- Font Customizing
- Theming
- Scripting / Extensions
- Integration with Alfred (and other external tools)
- Hot key / “Visor” window
- Interacting with on-screen text
- Image presentation
- Password Manager
Font Customization (strong win: Kitty)
Everyone has their own opinion on fonts, I’m currently using Fira Code with ligatures and the support that Kitty provides for fonts and their extra features is excellent. I can enable alternate zero and oldstyle numerals quite simply:
font_features FiraCode-Retina +zero +onum
And these settings can be applied to different fonts which makes sense because you can select glyphs from different ones. If you want some Nerd Font symbols in Kitty, we can easily assign those character codes to the Symbols Nerd Font (i.e. we don’t need any specific augmented font). This is amazing.
symbol_map U+E000-U+F8FF Symbols Nerd Font
Now Exa and other Nerd Font compatible apps works nicely:
Theming (win: Kitty)
Kitty has a built-in “kitten” to easily compare and setup themes:
kitty +kitten themes
Scripting / Extensions (winner: meh)
Both iTerm2 and Kitty have their oddities when it comes to scripting. Getting Kitty setup properly was confusing (I resorted to looking at the Kitty source code at one point…). In the end, I got it working and it works quite nicely. To enable the feature you have to set two options. First, set allow_remote_access yes
in order to allow access from other applications. The second option is listen_on
but if we enable it in the configuration file, Kitty will “helpfully” append on its PID which makes it inconvenient for scripting. To prevent Kitty from adding its PID, the option has to be set in the command line arguments. But for Mac users launching Kitty with Alfred or by just double-clicking, there can’t be any added arguments… Kitty supports this via a different configuration file.
# ~/.config/kitty/macos-launch-services-cmdline
--listen-on=unix:/tmp/mykitty --single-instance
The listen-on
argument here is what we want. The single-instance
is also a good idea, in my opinion.
After we launch Kitty, we can interact with it via commands like:
kitty @ --to=unix:/tmp/mykitty <SOME_KITTY_COMMAND_AND_OPTIONS>
This will come up as an example in the next section.
Integration with Alfred (winner: tie)
I use Alfred instead of Spotlight for its many features. I tried Raycast for the same reasons that I am trying Kitty now, but I’m not really sold on it, yet. To get Kitty to work as a custom terminal in Alfred, we’ll need an AppleScript. It took me a bit of searching and testing on my own to get it working how I like. What I ended up with is:
on alfred_script(q)
tell application "kitty" to activate
do shell script "/Applications/Kitty.app/Contents/MacOS/kitty @ --to=unix:/tmp/mykitty new-window --new-tab --cwd=current "
do shell script "/Applications/Kitty.app/Contents/MacOS/kitty @ --to=unix:/tmp/mykitty send-text \"" & q & "
\""
end alfred_script
This activates kitty, opens a new window, and then sends the query with a new line. I’m not great (or even competent) at AppleScript, so I’m sure this could be improved. The query can be passed with the new-window
command, but that causes the new window to close when the command completes.
Hot key / “Visor” window (winner: iTerm2)
I love the hotkey window feature of iTerm2. Always having the terminal instantly available in a consistent location is fantastic. However, this is not a feature of Kitty. It was suggested to use an Alfred hotkey to accomplish this and that works pretty well if you also assign Kitty to all desktops by right-clicking the icon in the dock.
Interacting with on-screen text (winner: Kitty)
Another feature of iTerm2 that I love is the ability to interact with arbitrary test presented on screen with triggers or auto-selection. This allows for really powerful features but it’s not always super reliable.
We use internal short-URLs and IDs for a wide range of things and I like to be able to click on them to open in different web front-ends. Kitty supports this through the “hints” kitten. Built-in is normal URL support, but I want some more obscure patterns and custom handling. I was able to use the regex
hint type with a simple script to take care of it. The key mapping below (⌘+g, b) searches the screen content for bug links like b/12345
and then let’s me select one to open_as_http
which is nice since our bug links commonly don’t have the http://
prefix.
map cmd+g>b kitten hints \
--type=regex --regex='b/\d+' --program=~/bin/open_as_http
The open_as_http
is a one line script:
open -a "Google Chrome" http://$1
Image presentation (winner: tie)
Yeah, it’s dumb, but I like to see images in the terminal. I do a lot of screenshot golden updates and this actually saves me a lot of time. iTerm2 has an imgcat
tool to do this and it seems that the icat
kitten is Kitty’s analog. Works pretty well. Unscientifically, it seemed faster.
Password Manager (winner: tie)
I have to type my password in the console a lot over the course of the day. iTerm2 has a built-in password manager, which is nice, but not necessary since Macs already have a powerful one built-in. The Keychain Access
app is pretty easy-to-use and the command line security
app is, as well.
Another Kitty user created a kitten to check for a password prompt then execute a command to fetch your password. The setup is pretty straightforward and you can configure the security options to your liking.
- Download the kitten from here into
~/.config/kitty/kittens
. - Add a keyboard mapping in your Kitty config.
- Add a generic password entry via the
Keychain Access
app. - Try a
sudo
command and then hit your shortcut.
My keyboard mapping uses the Name
of the password entry:
map cmd+BACKSLASH kitten \
kittens/password.py \
security find-generic-password -l "YOUR PASSWORD NAME" -w
You can try out the security
command on your own when testing.