Upgrade your command-line with these Rust-based tools.
Rust has achieved a certain notoriety among developers since its introduction. The language is complex, incorporates many incisive concepts, is compiled and, like C/C++, is a systems programming language. Yet Rust is more popular than any other. For years, Rust has topped the list in the annual StackOverflow Developer Survey as the most popular programming language and seems to be very common among hobbyist projects, especially on Github.
Although I am not able to assess exactly how the connection arose, the fact is that many well-known applications are being rewritten with Rust. Especially in the area of command line, the wheel is reinvented with pleasure and leads to a remarkable upgrade of the user experience, if one uses these programmes.
That’s what today’s TechUp is all about. We look at the most popular CLI-based Rust projects and I show you how to install and use them. 🦀👌
📦 Installing packages with Cargo
In the Rust landscape, Cargo is the reference tool to manage packages and build Rust-based projects. Now that we want to install Rust projects, it certainly makes sense to install Cargo on occasion as well, unless you prefer the OS’s own package manager.
The installation of Cargo is relatively simple and goes like this:
|
|
You have to confirm again with "1"
via inline command that rustup
is allowed to install Cargo, as well as other toolchain objects. When the tools are installed, we have to execute source "$HOME/.cargo/env"
. Once this is done successfully, we briefly check that a valid version of Cargo is present, and proceed immediately.
|
|
Installation example using exa
One of the first packages we want to install with cargo is exa
, a replacement for cp
. This can be easily installed with cargo install <package name>
.
|
|
Now you need to know that by default Cargo puts the binaries of the packages to be installed in a special user-specific root directory under ~/.cargo/bin/
. You can override this root target directory with the environment variable CARGO_INSTALL_ROOT
. In my example you can see that I have asdf (We also have a TechUp on asdf, check it out!) as version manager and asdf makes sure that for version 1.60.0
there is a separate root target directory under ~/.asdf/installs/rust/1.60.0/bin/
.
I could now override this directory with CARGO_INSTALL_ROOT
and have it point to the default ~/.cargo/bin/
. But we won’t do that here. Instead, I would like to mention that we should briefly check whether rustup
has added our root directory of choice to our shell via the $PATH
environment variable.
|
|
So far, so good. Now we can run exa
without further ado:
|
|
Hooray, hopefully we have learned something new here. Now we come to the actual question of today’s TechUp: Why should I want to use exa
and all these other tools at all? In the following, as promised, I will introduce you to some CLI tools that will take your command line to a new level. 🚀
exa - A modern replacement for ls
What is exa
? Well, exa
does pretty much the same as ls
, only better. Besides ls
, exa
is also a good replacement for tree
. A big advantage of exa
is that file formats and metadata can be distinguished using colours. More information can be found on the Github-Page of the project.
bat - A cat clone with wings
bat
is a replacement for the well-known cat
, but can also replace less
or more
. bat
supports syntax highlighting, git and other cool features. More information can be found on the project’s Github page.
du + rust = dust. Like du but more intuitive.
Disk usage, or rather du
, becomes even better with dust
. You can find more information on the Github-Page of the project.
tokei - 時計 Count your code, quickly
Tokei is a programme that shows you statistics about your code. It shows you the number of files and lines within those files, even grouped by programming language. Pretty cool. You can find more information on the project’s Github page.
fd - A simple, fast and user-friendly alternative to ‘find
fd
is like find
, but a bit simpler and more user-friendly. fd
is also more intuitive and faster than find
. For more information, see the project’s Github page.
tealdeer - A fast TLDR client
TLDR means “Too long; didn’t read” and is a slang acronym from the internet. There is a project with the same name, which manages simplified man pages maintained by the community. Tealdeer is a Rust implementation of this, with a focus on speed. More information can be found on the project’s Github page.
ytop - A TUI system monitor written in Rust
ytop
is like top
. It shows you all currently running processes and information about system resource usage, like CPU and RAM usage. Unfortunately, the project has been discontinued, so I’ll introduce bottom
next. You can find more information on the project’s Github page.
bottom - A customizable cross-platform graphical system monitor for the terminal
bottom
is like top
or ytop
. For more information, see the project’s Github page.
Integrating into everyday life via aliases
Now we want to integrate all these utilities into our everyday life, i.e. define them as aliases in all the shells we use.
Here, for example, is an excerpt from my ~/.zshrc
:
|
|
After that we still have to reload the configuration in the existing TTY session with source ~/.zshrc
. If you use a shell other than zsh
, you have to change the command accordingly: source ~/.<your shell>rc
.
Further sources and resources
https://github.com/matu3ba/awesome-cli-rust
https://gist.github.com/sts10/daadbc2f403bdffad1b6d33aff016c0a