SECRET OF CSS

Unleashing Your Terminal With Kitty and Zsh | by Kevin Suñer | Jul, 2022


Make your development a breeze

1*1iIJRt2WoGt8LENyNC z3A
Photo by Zhang Kaiyv on Unsplash

Many of us spend a considerable amount of hours inside a thing called the Terminal yet many stay with the default one that comes with their OS and sticks with it indefinitely, and nothing wrong with that, but have you thought about how much more easy could your life be if you spent a tiny bit of time fine-tuning it?

Here I will try to lay the grounds for what I hope will be your never-ending journey of tailoring a terminal to your needs. Since I do not recommend things that I haven’t used on a daily basis for quite some time in this tutorial I’m going to show you how to set up and customize Kitty and Zsh to step up your terminal game.

There are quite a lot of options in the world of terminal emulators, each one of them can appeal to different types of users, some can have a more retroish feel, while others aim for being minimal and focus on what’s important rather than having a lot of bells and whistles.

In my experience Kitty belongs to the minimal ones, that doesn’t mean that you can’t do a whole lot of things with it, no, you can customize it entirely and make it your own thing. By minimal I’m referring to the way it lets you do those adjustments which, in this case is quite straightforward, just keep reading, you will see what I’m talking about in a minute.

Apart from that Kitty uses your GPU to do the rendering, which makes it fast, really fast, you can notice this by how low the latency between you typing and the text appearing on the screen is, furthermore they allow you to do some more performance tuning if you wish to.

You have many options, but for the sake of simplicity and to not overburden this story I will showcase two ways of installing it, one for those who like stability and one for those who like living on the edge.

Install the pre-built binaries of Kitty if you are on macOS or Linux running the following command:

$ curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin

If you wish to you can set some parameters to specify a different installation location or to tell Kitty not to launch after installation:

$ curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin \\ dest=/some/other/location launch=n

And if be it for fun, curiosity or madness you want to install and live on the nightly version you can do it by running this command:

$ curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin \\ installer=nightly

For further reference please refer to the well-made documentation that the people working in Kitty have made Installation Guide.

This section tends to be more personal since each one has it’s own preferences, so I’m not going to go with full-blown customization, instead, I’m going to show you the basics so you can start building on top of that.

Themes

When I was starting to tinker with Linux and its terminal one thing that infuriated me was not knowing or not being able to find an easy way to change its color scheme, thus one of the things that I look for in a terminal emulator is the ability to switch themes with ease.

Kitty and more specifically a member of its community called Dexpota do a fantastic job in this matter with repos such as kitty-themes which allows you to download and apply a gazillion themes.

Downloading a specific theme from the repository:

$ THEME=https://raw.githubusercontent.com/dexpota/kitty-themes/master/themes/Brogrammer.conf
$ wget "$THEME" -P ~/.config/kitty/kitty-themes/themes

Creating a symlink to the downloaded theme:

$ cd ~/.config/kitty
$ ln -s ./kitty-themes/themes/Brogrammer.conf ~/.config/kitty/theme.conf

Creating a kitty.conf file and adding the downloaded theme:

$ echo "include ./theme.conf" > kitty.conf

And that’s it close your Kitty terminal and open it up again to see the changes, simple as that, want to change theme again? Repeat steps 1 and 2, close, open, voila!

Fonts

When it came to choosing a font I didn’t have a clear preference, as long as it was readable and consistent it was fine for me, but time passed and I started to dig deeper on the topic and found that there where certain fonts that aimed to facilitate development, you had to find them but it wasn’t to much of a hassle.

But then Ryanoasis came with a thing called Nerd Fonts which is a collection of patched fonts for developers, and it’s the thing that we are going to use to set up a custom font in Kitty.

Downloading a specific directory from the repository. Requires Git v2.26:

$ git clone --filter=blob:none --sparse git@github.com:ryanoasis/nerd-fonts
$ cd nerd-fonts
$ git sparse-checkout add patched-fonts/Hack

Installing a single font:

$ ./install.sh Hack

Creating a font.conf file and adding the downloaded font:

$ cd ~/.config/kitty
$ echo "font_family Hack Nerd Font Mono" > font.conf

Finally, you can add the font.conf file to your kitty.conf file by opening the file and adding an include ./font.conf directive. close your Kitty terminal, open it again, and the new font should be there for you to enjoy it.

Obviously, this is just the tip of the iceberg, Kitty is extremely customizable and a quick look at their Configuring Kitty section will probably make you wonder about all the things that you can do to improve it.

The driver is ready to rock, now in order to go up a notch you will need to setup a command interpreter that suits your needs and lets you customize it to your liking. Without going into a debate about which one is better and whatnot I’m going to choose the simple route and recommend what I have used extensively as I did with Kitty.

Zsh is a powerful and interactive command interpreter that not only serves as a shell but also serves as a scripting language, one of the main benefits is that it can be easily extended with plugins, making your terminal look like it’s on steroids.

Like Kitty there are many ways to install it, but for now let’s keep it nice and easy by looking at how to installing for macOS and Linux, which support bash unlike Windows.

Checking if you already have Zsh installed:

$ zsh --version

Installing Zsh:

# For macOS users
$ brew install zsh
# For Ubuntu/Debian
$ apt install zsh

Making Zsh your default shell:

# For macOS users (latest versions)
$ chsh -s /usr/local/bin/zsh
# For macOS users (High Sierra and older)
$ chsh -s /bin/zsh
# For Linux users
$ chsh -s $(which zsh)

After that, all you have to do is a logout/login from your computer account, and the next time you open Kitty you will be noticed with a menu containing a few options, choose 0 and don’t panic, I know it looks awful at the moment, but it won’t last that way for too much.

Prepare for the ride, you are about to witness a delightful transformation courtesy of Oh My Zsh which is an open-source framework that comes bundled with awesome features to make development easier and more enjoyable.

Installing Oh My Zsh

As we already have Zsh up and running, installing Oh My Zsh is a matter of running one simple command.

# Using curl
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Using wget
$ sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Using fetch
$ sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Themes

By default Oh My Zsh comes with a theme called robbyrusell which is the name of the creator, but if you take a look at the themes section from the wiki page there are a ton of options for you to choose.

Switching from one to another is easy as renaming a variable, let me show you.

Editing the .zshrc file.

$ nano ~/.zshrc

Note: I’m using nano but you can use whatever you want to edit it.

Renaming the ZSH_THEME variable.

ZSH_THEME="theme-name" # e.g., half-life

Then all you have to do is save the file and either restart Kitty or refresh the .zshrc file by running the following command source ~/.zshrc.

Plugins

Another really cool feature about Oh My Zsh is that it also acts as a plugin manager, allowing you to install a quasi infinite amount of useful tools made by other developers.

The first one that we are going to install will help you to notice if you are typing in the right command or not, I’m talking about zsh-syntax-highlighting but for your terminal, isn’t that cool!

Installing the zsh-syntax-highlighting plugin.

$ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Activating the plugin in the .zshrc file.

plugins=(
# other plugins...
zsh-syntax-highlighting
)

Restart Zsh either by closing or peforming a source ~/.zshrc

And the second one that we are going to install will help you to write different commands flawlessly, I’m talking about zsh-autosuggestions to help you remember and autocomplete stuff that you type in regularely, thus making you more efficent and less prone to type the wrong thing.

Installing the zsh-autosuggestions plugin.

$ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

Activating the plugin in the .zshrc file.

plugins=(
# other plugins...
zsh-autosuggestions
)

Restart Zsh either by closing or performing a source ~/.zshrc

Phew! that was intense.

You learned quite a few things here, things that I hope serve you in your path and make life easier for you, this topic in itself can go down a rabbit hole experience quite fast, as there is no limit to the amount of customization you can achieve using Kitty and Zsh.

In this tutorial, you have only put the tip of your toe in the water, now that you have the base is up to you if you want to go further.

I’ll give you a clue about a thing that you may want to look at, and that is Kittens which is a way to extend Kitty, but on the other hand, if you want to leave it as it is, that’s completely fine, you have a rather productive terminal that will get you where you want to go.

Nevertheless, it’s been a pleasure sharing the tools that I personally use in my day-to-day as a developer. Thanks for reading.



News Credit

%d bloggers like this: