Completely Oxidizing My Terminal Setup
Tags: rust, shell, productivity
Published: 2021-07-22 10:44:00

Hello!
I recently oxidized my terminal setup, by converting all of my terminal programs to rust based programs. There were some hiccups in making it all work together, but in the end, my new setup is :
* [Alacritty](https://github.com/alacritty/alacritty) as my terminal emulator
* [Starship](https://starship.rs/) as my shell prompt
* [nushell](https://www.nushell.sh/) as my shell
* [zellij](https://www.nushell.sh/) as my terminal multiplexer

Note : nushell and zellij both are still in their beta versions, and have few [known issues](https://github.com/zellij-org/zellij/issues/615), so if you want an absolutely reliable env, use bash/fish/zsh for shell and screen/tmux for terminal multiplexer.

## Original setup
Before changing this, I had already installed Alacritty and starship and had used it for few days before switching back to default gnome terminal emulator with starship. The main reason I switched back was that a lot of times I ran multiple processes in parallel, such as running react frontend and node backend. I was used to doing this using the tabs of gnome emulator, and as Alacritty has clearly specified in its Readme, it has no intention of adding a terminal multiplexer, and users would need to use an external one such as tmux to do that (Which makes sense).

Unfortunately, I didn't want to install and setup another program to make it work, and I needed the functionality of multiplexed terminals in single window, rather than opening a new window each time ; which is why I moved back to gnome terminal emulator. In this, I kept starship, as I really liked it, and it was quite useful.

## A second look
I had checked out nushell about a year ago, and it seemed very interesting, but then I felt it was a little too complex, and I felt like I wouldn't need all the features it provides, so I didn't try using it.

Few days back, I came across [this](https://www.poor.dev/blog/performance/) retweeted by official Rust twitter account, which explained how zellij, a rust terminal workspace solved some of the performance issues. (It is really well writter, do check it out!)

While checking out zellij, I remembered nushell, and went back to its site to check that out as well. This time it didn't felt as complex, as well as its features looked awesome (you can "preview" an image in the terminal itself :astonished: :astonished: ).

With this, I decided to convert all my terminal setup to Rust.

## Upgrading
I had already installed alacritty as per their [installation guide](https://github.com/alacritty/alacritty/blob/master/INSTALL.md), as well as had starship set up. Now I had to install and setup nushell and zellij.

Installation process was quite straightforward, using cargo, and for nushell I had to install some other libraries for extra features using apt-get, but it went smoothly following the instructions on their pages :
* [nushell](https://www.nushell.sh/book/installation.html)
* [zellij](https://zellij.dev/documentation/installation.html)

After the installation, it was time to set it all up together, where I hit a couple of issues. First, I wanted to integrate zellij with alacritty and nushell, so that it can manage multiple sessions.

Initially I though setting the startup command in nushell to zellij would work, as startup command are run at start of each shell session. But quickly I found out I was wrong, as after starting nushell, it would first run zellij, which would keep running with default bash shell, and thus nushell would not actually run until I quit zellij.

Then I found out that zellij can be launched with specific shell as an argument, and alacritty has an option to choose which shell to run in its configuration, which was great because I didn't want to change system default shell to nu (its still in beta).

So first, I copied default `alacritty.yml` to my home directory. The default file comes when installing from source, or else can be copied from their github repository. It has an option somewhere in the middle for shell :
```yaml
# Shell
#
# You can set `shell.program` to the path of your favorite shell, e.g.
# `/bin/fish`. Entries in `shell.args` are passed unmodified as arguments to the
# shell.
#
# Default:
#   - (macOS) /bin/bash --login
#   - (Linux/BSD) user login shell
#   - (Windows) powershell
#shell:
#  program: /bin/bash
#  args:
#    - --login
```

It is commented by default. I thought uncommenting and changing it to zellij , and passing the option to set shell to nushell would work, so I set it to :
```yaml
shell:
  program: ~/.cargo/bin/zellij
  args:
    - options --default-shell nu
```
Which ... didn't work. Whenever I would launch alacritty, and it would immediately close, with no error message. I tried opening it from commandline of gnome shell, but it didn't leave any error message there, and that lead me to go through its github issues, and find how to make it generate debug dump, which I though would be helpful to find what is the issue, ... but it didn't work either :sweat_smile: :smile:

After that I figured that it might be possible that it might be because I was giving all the arguments to it in a single arg. Usually when we give args, program gets them as array of strings, and then it can parse it, and [I think] shell splits it by space to form the array. But in this, all was in a single arg entry, and thus was getting sent to program (zellij) as single argument, instead of 'options' , '--default-shell' and 'nu' being separate args.

After figuring this out, I separated them as individual args, and finally my config looks as :

```yaml
shell:
  program: ~/.cargo/bin/zellij
  args:
    - options
    - --default-shell
    - nu
```

and viola! It worked. Now I had to only set starship as shell prompt which was easy, as nushell has that as an [example](https://www.nushell.sh/book/configuration.html#prompt-configuration). And my terminal setup was ready and oxidized. :tada: :tada: :tada:

Now it looks like :

![screenshot of my terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/anna7hf79utr21eom0w7.png)

![use example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ojek6l1fk9sonunm4bpc.png)

So, did you find this interesting or helpful? 
Did you already used any of these , or thinking of trying them out?
Let me know in the comments!

Thank you!