sebastiandaschner blog


Modern Linux Terminal With Alacritty, JetBrains Mono & Emojis

#linux #commandline saturday, february 04, 2023

You might know that I’ve been a heavy user of Linux and the Linux command line for a while. When you spend a lot of time in any environment, the layout and fonts are something to consider. For my demos, examples, and own projects, I wanted to have a setup with a nice coding font as well as (good-looking) emoji symbols. In the following, I’ll explain my current setup that uses Alacritty as terminal emulator, Zsh, JetBrains Mono, and Noto Color Emoji.

At first it sounds like a rather obvious and easy task — and assuming such a thing under Linux is always dangerous ;) — to have a setup both with a nice coding font and good-looking emojis.

I’ve been using JetBrains Mono for a while, in my IDE as well as command line setup and I’ve been very happy. Well, recently some letters have been slightly changed and actually I’ve noticed this after a system update — and at first I blamed my Linux for not loading the correct font after updating — but in fact the font was altered. I’m very sensitive to changes in how something looks — e.g. I always detect broken pixels, things that are slightly off, syntax errors and so on, which is both a blessing and a curse — and for this reason, I was annoyed that my terminal now looks a bit different and I switched back to JetBrains Mono 2.242, but that’s only me.

As for emojis on the command line, it turned out that this was in fact not easy at all, since most emoji fonts use a variable width that a lot of terminal emulators, such as the rxvt-unicode I’ve been using before, can’t deal with. So, I’ve tried around for some of the patches that are available for this terminal for my ArchLinux, but they had other issues.

After trying a few terminal emulators, I’m now using Alacritty, and am quite happy. At first, using a true color emulator as opposed to 256-bit color is a slight difference when colors don’t look the way you expect them, but after some tweaking it worked well. Maybe it helps some folks to describe what I had to do in their setup as well.

 

Alacritty

The terminal comes with nice defaults and an easy way to configure, e.g. using ~/.config/alacritty/alacritty.yml. The website doesn’t list all of the configuration examples, so the best is to look under /usr/share/doc/alacritty/example/alacritty.yml for the comments. It nicely automatically reloads everything once you save the file, so it’s easy to try out.

For your reference, this is my alacritty.yml config file:

# ~/.config/alacritty/alacritty.yml
font:
  normal:
    family: terminal-font
    style: Regular

  bold:
    family: terminal-font
    style: Bold

  italic:
    family: terminal-font
    style: Italic

  bold_italic:
    family: terminal-font
    style: Bold Italic

  size: 8
  offset:
    x: 2
    y: 1

colors:
  primary:
    background: '#000000'
    foreground: '#ffffff'
  cursor:
    text: '#000000'
    cursor: '#f39d21'
  vi_mode_cursor:
    text: '#000000'
    cursor: '#f39d21'

  normal:
    black: '#000000'
    red: '#e84f4f'
    green: '#b8d68c'
    yellow: '#e1aa5d'
    blue: '#7dc1cf'
    magenta: '#9b64fb'
    cyan: '#6d878d'
    white: '#dddddd'
  bright:
    black: '#404040'
    red: '#d23d3d'
    green: '#a0cf5d'
    yellow: '#f39d21'
    blue: '#4e9fb1'
    magenta: '#8542ff'
    cyan: '#42717b'
    white: '#000000'

window:
  padding:
    x: 2

The colors are just my preference of what I was used to with my previous setup with Zsh on top of rxvt-unicode. What’s this terminal-font, you might ask? Well, I’m glad you’re asking…​

 

JetBrains Mono & Noto Color Emoji

Setting up the fonts was indeed again a bit harder than thought, since this terminal emulator only configures a single font family. The easiest was to trick the Linux setup to combine the desired fonts, so that at first, for most characters, JetBrains Mono is taken, and Noto Color Emoji only for those who aren’t provided yet by the first font. That’s easier to do than thought, simply put a fontconfig under ~/.config/fontconfig/fonts.conf and force-refresh the font cache with fc-cache --really-force.

This fontconfig sets up a font alias terminal-font for both fonts in the desired order:

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>

  <alias>
    <family>terminal-font</family>
    <prefer>
      <family>JetBrains Mono</family>
      <family>Noto Color Emoji</family>
     </prefer>
  </alias>

</fontconfig>

That’s how we can use this font family name in our terminal config.

To test the whole thing, insert plain text and a few emojis into your terminal. I’m using the rofimoji emoji picker for my rofi launcher.

alacritty emoji fonts

 

Once you have this setup, the emojis should also work in your terminal editor such as Vim, if you use one.

 

Presentation Setup

But wait, there’s more. I’m using the command line not only for my own coding, but of course also for presenting, both directly by showing stuff that I type, and also using Vim, since I give my presentations in Vim.

For this, you want a bigger font and sometimes also a light theme.

This works quite nicely in Alacritty as well, by using symlinks. Alacritty allows to import configuration files in your alacritty.yml, so you can have a small hierarchy of files, a default one, and and a few optional ones (set up by a symlink) that you include or not.

For this, you change your setup to something similar like:

~/.config/alacritty $> ls -ahl
lrwxrwxrwx   9 sebastian 31 Jan 10:29 active.yml -> /dev/null
.rw-r--r--  79 sebastian 30 Jan 13:39 alacritty.yml
.rw-r--r-- 839 sebastian 31 Jan 12:57 default.yml
.rw-r--r--  57 sebastian 30 Jan 13:47 video.yml

The alacritty.yml includes both the default.yml and active.yml (in this order). The active.yml might point to the video.yml or another, or simply to /dev/null for which it is ignored.

My default.yml contains the same config as seen above, the alacritty.yml changes to the following:

import:
  - ~/.config/alacritty/default.yml
  - ~/.config/alacritty/active.yml

This is the normal setup and results in the same terminal config as before.

If I want to switch to a presentation setup, I (of course) have a script for this, that redirects the symlink to video.yml (or others for more choices):

~/.config/alacritty $> presentation-mode video
enabling video-mode
~/.config/alacritty $> ls -ahl
lrwxrwxrwx   9 sebastian  4 Feb 08:19 active.yml -> video.yml
.rw-r--r--  79 sebastian 30 Jan 13:39 alacritty.yml
.rw-r--r-- 839 sebastian 31 Jan 12:57 default.yml
.rw-r--r--  57 sebastian 30 Jan 13:47 video.yml

The presentation-mode script performs either ln -fs video.yml active.yml for enabling (setting the symlink to video.yml) or ln -fs /dev/null active.yml for disabling the bigger fonts.

My video.yml looks as follows:

font:
  size: 19

colors:
  bright:
    white: '#dddddd'

This overrides the font size and color and leaves the other options untouched.

With such a setup, one can now build up different scenarios depending on the needs.

 

Resources

You can find my example setup in my Dotfiles repository.

I’m using the following components:

  • Zsh with oh-my-zsh

  • Alacritty as terminal emulator

  • JetBrains Mono version 2.242

  • Noto Color Emoji (installed with ArchLinux noto-fonts-emoji)

 

Found the post useful? Subscribe to my newsletter for more free content, tips and tricks on IT & Java: