Upgrade your command line with these Rust-based tools.

20.07.2022Raffael Schneider
Tech Rust CLI Productivity Core Utilities

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
❯ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
...
Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source "$HOME/.cargo/env"

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.

1
2
❯ cargo --version
cargo 1.60.0 (d1fd9fe2c 2022-03-01)

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>.

1
2
3
4
5
6
7
8
❯ cargo install exa
    Updating crates.io index
  Downloaded exa v0.10.1
  Downloaded 1 crate (136.6 KB) in 0.60s
         ...
    Finished release [optimized] target(s) in 1m 12s
  Installing /Users/rschneider/.asdf/installs/rust/1.60.0/bin/exa
   Installed package `exa v0.10.1` (executable `exa`)

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.

1
2
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:...:/Users/rschneider/.cargo/bin

So far, so good. Now we can run exa without further ado:

1
2
❯ exa
Applications Desktop Development Documents Downloads Library Movies Music Pictures Public

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# ...
alias p="pwd
alias c="curl
alias vim="hx"
alias vi="vim
alias exa="exa --icons"
alias ls="exa --icons"
alias tree="exa --icons -T"
alias t="tree
alias less="bat --paging=always"
alias cat="bat -p --paging=never"
alias du="dust
alias top="ytop"

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://rustup.rs/

https://crates.io/

https://github.com/matu3ba/awesome-cli-rust

https://gist.github.com/sts10/daadbc2f403bdffad1b6d33aff016c0a