Terminal: Installing and customizing the Kitty terminal emulator on Linux ver. 7

Last Updated on September 24, 2022 by shibatau

IV is corrected and V is added.

I. What is Kitty

Kitty is the fast, feature-rich, GPU based terminal emulator, which is available for macOS and Linux.

II. Installation (Ubuntu)

Run the commands in the terminal

sudo apt update

sudo apt-get install kitty

You can learn more here:

How to install and customize the Kitty terminal emulator on Linux

III. Customization

Create a directory.

mkdir -p ~/.config/kitty/

Create a config file:

touch ~/.config/kitty/kitty.conf

Edit kitty.conf with your editor.

YOUREDITOR ~/.config/kitty/kitty.conf

You should write something like this and save it.

font_family monospace
bold_font auto
italic_font auto
bold_italic_font auto
font_size 13.0
foreground #DBDBDB
background #002B36

You can learn more here:


IV. Display an image in the terminal

Run the code to preview an image in the terminal:

kitty +kitten icat path/to/some/image.png

You can learn more here:

Terminal graphics protocol

You cal also display PNG images in Kitty using Python code:

import sys
from base64 import standard_b64encode

def serialize_gr_command(**cmd):
    payload = cmd.pop('payload', None)
    cmd = ','.join(f'{k}={v}' for k, v in cmd.items())
    ans = []
    w = ans.append
    w(b'\033_G'), w(cmd.encode('ascii'))
    if payload:
    return b''.join(ans)

def write_chunked(**cmd):
    data = standard_b64encode(cmd.pop('data'))
    while data:
        chunk, data = data[:4096], data[4096:]
        m = 1 if data else 0
        sys.stdout.buffer.write(serialize_gr_command(payload=chunk, m=m, **cmd))

with open(sys.argv[-1], 'rb') as f:
    write_chunked(a='T', f=100, data=f.read())

Save the code above as png.py. In the directory where the ping.py file is located, run the code:

python png.py path/to/some/image.png

Here is the image for that:

V.If you are requred to install Image Magick

I’m required to install Image Magick on my Linux disttribution – Kali Linux (Debian). So I have installed Image Magick following the instruction:

How to Install ImageMagick on Debian 11

But I got an ImageMagick security policy error when I tried to preview a PDF file. To preview it I tried to remove the following lines from /etc/ImageMagick-6/policy.xml .

<!-- disable ghostscript format types -->
<policy domain="coder" rights="none" pattern="PS" />
<policy domain="coder" rights="none" pattern="PS2" />
<policy domain="coder" rights="none" pattern="PS3" />
<policy domain="coder" rights="none" pattern="EPS" />
<policy domain="coder" rights="none" pattern="PDF" />
<policy domain="coder" rights="none" pattern="XPS" />

But I got E212 Can’t open file for writing when I tried to save the file with :w in Neovim. So I’ve opened the policy.xml file with Vim and run the following command. I couldn’t save the file when I used Neovim.

:w !sudo tee %

Now I can show a preview for a PDF file:

You can learn about this from the posts:

Vim Can’t Save File (E212)

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.