alacritty-themes not working any more!!!
Published: 2024-01-07 16:56:54

## Introduction to Alacritty: A Lightweight Terminal Emulator

Alacritty, known for its speed and efficiency, stands out as a lightweight and GPU-accelerated terminal emulator. Striking a balance between simplicity and performance, Alacritty has become a popular choice among users seeking a fast and responsive terminal experience.

## Navigating the Transition: From alacritty.yml to alacritty.toml

As Alacritty evolves, so does its configuration. If you don't know before version `0.13.0 (78fa4d6f)` alacritty.yml was used as its configuration file. The shift from using alacritty.yml to alacritty.toml brings about a need for users to adapt their customization strategies. In this article, we explore a practical workaround to ensure a seamless transition, specifically addressing the challenge presented by tools like alacritty-themes that were originally tailored for the YAML configuration.

The alacritty-themes was an excellent npm package which as its name suggests was used for theming alacritty. these features made it good at what it was made for

- Live preview of the themes
- 200+ Themes to choose from
- Apply any theme with just one command at the terminal
- Option to create your alacritty.yml config file
- Simple, Easy and intuitive User experience

{% embed https://github.com/rajasegar/alacritty-themes %}

But this tool was made for alacritty.yml files and seeing the last commit on it which was 7 months ago as of writing this post, it seems like it will be a while before they fix this problem. 

So for this, I found a temporary workaround not as great as the tool. 

First, let's move all your alacritty.yml to alacritty.toml for this you'll need to learn toml file format and re-write your entire configuration from yaml to toml, good let's start from the basics. hehe just kidding just run this command 

```
alacritty migrate
```

Now your alacritty.yml has been converted to alacritty.toml.

Now let's collect some themes we'll use this official alacritty repo of themes collection all are in toml format.

{% embed https://github.com/alacritty/alacritty-theme %}

Clone this repo where your alacritty.yml file is for it was at `~/.config/alacritty/` so I cloned it there
Use these commands

```
# We use Alacritty's default Linux config directory as our storage location here.
mkdir -p ~/.config/alacritty/themes
git clone https://github.com/alacritty/alacritty-theme ~/.config/alacritty/themes
```

Now go to your `.bashrc` or `.zshrc` or whatever your configuration file is for your shell environment and create a `alias` add this line 

```
alias themes="ls ~/.config/alacritty/themes/themes | fzf | xargs -I {} ln -sf ~/.config/alacritty/themes/themes/{} ~/.config/alacritt
y/current_theme.toml && echo "@@@" >> ~/.config/alacritty/alacritty.yml && sed -i '/@@@/d' ~/.config/alacritty/alacritty.yml"

```

To understand what this command is doing let's break it into 4 parts

1. `ls ~/.config/alacritty/themes/themes` This part is just listing the theme files that we git cloned.

2. The above command's output is piped into fuzzy finder `fzf`. You can find the installation instructions at {% embed https://github.com/junegunn/fzf %}

3. Now the output of fuzzy finder is piped into `xargs -I {} ln -sf ~/.config/alacritty/themes/themes/{} ~/.config/alacritt
y/current_theme.toml` This is creating a symbolic link at `~/.config/alacritty/current_theme.toml` for the theme file that you selected in fuzzy finder like if you selected gruvbox.toml in fzf it'll create a symbolic link for `~/.config/alacritty/themes/themes/gruvbox.toml` to here `~/.config/alacritty/current_theme.toml`.

4. The last part is this `echo "@@@" >> ~/.config/alacritty/alacritty.yml && sed -i '/@@@/d' ~/.config/alacritty/alacritty.yml` this is just appending a `@@@` string at the end of the alacritty.toml file and removing it I'll tell you the reason for this later.

okay now you just need to add this line to your alacritty.toml file 

```
import = [
    "~/.config/alacritty/current_theme.toml"
]
```
Remove any color scheme in your toml file because if there is already manual color scheme the import of the theme file will not work. All should work now just enter your alias command > choose the theme > press enter and that's it.

Now to explain the reason for the 4 part is that remember we created a symbolic link at `~/.config/alacritty/current_theme.toml` for the theme file we'll select and have added an entry of importing it in alacritty but as you'll run the complete command you will not see any color scheme change that is because you have changed the content of  `current_theme.toml` (more specifically it's redirection location) not the content of `alacritty.toml` and alacritty only refreshes if it detects any changes in it's configuration file the complete command (the 4th part) cause some change in file by adding `@@@` and removing it next so the color scheme refreshes.