Rust Ecosystem for the Linux terminal#
Besides my personal interest in this language, I am also interested in the ecosystem of tools that have been developed in Rust for the Linux terminal and for supporting other programming languages (like its impact on Python, which is my main development language).
I previously told you about Starship, and next we are going to expand this universe of Rust possibilities for the Linux terminal.
Accelerate your work in the terminal#
While Zsh is not implemented in Rust, this terminal language (shell) is very powerful and flexible, with a large number of plugins available to customize and improve its experience. So I take advantage as part of my newly reloaded Linux terminal to include it and tell you about how to switch to using it by default. Additionally, this is necessary to mention since, the configuration will require knowing our shell, and this defines why the instructions we are going to learn. I still use it like a general bash, but I have already seen very interesting things that I will soon share.
Just as we saw the extra information experience that Starship offers us, we are going to explore utilities that help us improve our fast experience in the terminal with greater agility in our workflows.
We will start with zoxide, a replacement for cd that allows us to navigate through
our directory history faster and more efficiently. It has
autocomplete and priority assignment for directory shortcuts.
We can use it by indicating a short form of the directory or similar, and through
fuzzy search in the directories we have already navigated (using zoxide as
a usual cd) it can guess the directory we are looking for, or if we know that
there can be several directories with the same name, it can show a list
of options to choose from when typing space and tab.
We can also speed up our experience with a terminal emulator in Rust like Alacritty, which offers a faster and more efficient interface than the default Linux terminal, and its rendering is with OpenGL. This emulator is also available on MacOS and Windows, and has a Vi mode for navigation, as well as extended selection options and opening links with the mouse.
Alacritty does not have a multiplexer, but we can give it this capability through Zellij, a terminal multiplexer (this allows us to have multiple windows and panes within a single terminal). We can have floating panes, custom layers and a series of shortcuts to do proper navigation. A lock mode is available to avoid confusion with system shortcuts, and this is used with Ctrl+g, and there the shortcuts p for pane management or t for tab management, and with options to create (n), close (x), navigate (arrows), among others. We can generate floating panes with Alt+f (which can then be moved with the mouse) or normal panes with Alt+n. To navigate in this mode, we can use Alt with arrows.
And finally, a terminal editor with Vi mode support, quite comfortable to use and with native tree sitter and LSP support. This editor is Helix. And it has become my favorite terminal editor and I have linked it as the editor for git editing.
Now, let’s get down to business to install and configure.
In Manjaro (and Arch derivatives) we have the necessary packages in the official repository.
pamac install zsh alacritty zellij zoxide helix --no-confirm
pamac install --as-deps fzf --no-confirm # Interactive search for zoxide
To configure zsh as your default shell we proceed as follows:
chsh -s /bin/zsh # Configure default shell: enter password
You may need to restart your session for the change to take effect. Then, we can configure the other utilities that depend on the shell to know the configuration options.
Zoxide requires executing its initialization script indicating the shell
that is being used. Depending on the installation method, you might need to check the
associated executable, in my case it stays as z and I feel comfortable with it.
echo 'eval "$(zoxide init zsh)"' >> ~/.zshrc
source ~/.zshrc
In the case of Alacritty, we must indicate the shell that is being used in the configuration file (TOML format) and incidentally we will link the use of Zellij at its startup.
mkdir -p $HOME/.config/alacritty
cat << 'EOF' > $HOME/.config/alacritty.toml
[terminal.shell]
args = ["-l", "-c", "zellij attach --index 0 || zellij"]
program = "/bin/zsh"
EOF
Regarding the use of Zellij, I recommend the unlock first mode to avoid collision of shortcuts that we have in the system (it is a bad experience). To configure it, inside a Zellij session, press Ctrl+o followed by C to open the configuration, then use Tab, down arrow to option 2 (“Unlock First”), and finally Alt+a to save the changes.
Remember also to configure starship so you have the complete combo.
Finally, for Helix to be your default editor in the console, you must configure the EDITOR environment variable. You can append it to your shell configuration:
echo 'export EDITOR=helix' >> ~/.zshrc
source ~/.zshrc
Associate Alacritty as default terminal in KDE.#
At this point we have the basics ready, and if you launch directly alacritty nothing else is needed. However, if you use terminal shortcuts or there are applications that launch the terminal that is associated by default, they will continue to launch the terminal (emulator) that you had before. So that this does not happen, you will have to do some additional steps that depend on your desktop environment. In my case, since I use KDE, the steps are the following.
To link alacritty as the default terminal emulator:
To configure the keyboard shortcut: We configure the “Launch” shortcut by clicking Add, and after that the desired shortcut. In my case I prefer the usual terminal one Control-Alt-T. We apply the change (Apply).
New ecosystem of utilities#
We have here a replacement for our favorite console commands, which we take advantage to modernize with Rust and in some cases to have an important performance improvement (in their reimplementation) or of agility with the new options they offer us.
bat: Replacement forcat. I highlight its syntax coloring, git change marks and the option to show invisible characters.bottom(btm): Replacement fortop. It has cross-platform support and process management allows you to kill them there (you select the process and then d d)eza: Replacement forls. I haven’t explored much of its potential yet, but its default coloring is much more useful to me than the original one. It allows knowing additional information of the files and directories during the query, such as their git status or mount point information.procs: Replacement forps. Cross-platform, and with better readability than the original.du-dust(dust): Replacement fordu. Its default visualization seems much more informative than the original command.
Now, let’s proceed to install.
In Manjaro (and Arch derivatives), we again have everything available in the official repository.
pamac install bat bottom dust eza procs --no-confirm
In Ubuntu, we will need to mix the official repository with the Rust repository.
sudo apt install -y bat du-dust eza
cargo install --locked bottom procs
References#
Now that we have rusted our Linux terminal, I invite you to visit the official information of these projects.
You can learn more Rust utilities for your console here.