Awesome CLI Toys

comp
@softwares
en
#cli
#awesome

Some nice CLI utilities that can cure your internal mental consumption.

Note that the mental consumption introduced by installing or building from source are not considered.

Also note that this article DOES NOT intend to deliberately stress the fact that the Rust language specializes solely on rewriting CLI tools with fancy ANSI escape codes.

Zsh

zsh zsh is quite a powerful and configurable yet old-schooled shell(comparing to fancy REAL GEN-Z stuff like warp or nushell). Traditionally you would want to install the famous bloatware oh-my-zsh as a drop-in configuration framework. Wait a minute, this is a shell, not a CLI🤪.

# Install `oh-my-zsh`
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

# Install `oh-my-zsh` with Gitee mirror
sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"

Then, it would be delightful to have syntax highlighting, completions and auto suggestions.

# Cloning
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

# Install via `omz`
omz plugin enable zsh-syntax-highlighting zsh-completions zsh-autosuggestions

Zoxide

zoxide is a Rust implementation of smart working directory changing tools like autojump and z. It remembers your previous browsing records, so a tiny fraction of path suffices your next navigation to this directory.

Demo

zoxide demo

z ~/a/very/long/path/with/a-long-name

# The next time you want to jump to that directory:
z a-lo

Read the full installation instructions here.

# Install on Linux
# This script is COMPATIBLE with local installation
curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash

# ADD the init script to your `.zshrc` 
eval "$(zoxide init zsh)"

# OR use `omz` plugin for `zoxide`
omz plugin enable zoxide

# ALIAS `cd` to `z`
alias cd="z"

Starship

Although themes like powerlevel10k or rubbyrussell or random looks pretty nice, sometimes you might have to cope with the recognized best Linux desktop environment, namely Windows. It would have been a nightmare trying to sync your pwsh theme with your zsh counterpart. starship starship provides a unified and configurable cross-shell prompting environment, which suits this need perfectly.

Demo
# Install on Linux
# This root is INCOMPATIBLE with local installation!
#   manually set the env var to install it locally.
export BIN_DIR="/usr/local/bin"
curl -sS https://starship.rs/install.sh | sh

# ADD the init script to your `.zshrc`
eval "$(starship init zsh)"
# Install on Windows with `scoop`
scoop install starship

# ADD this line to your Powershell profile ($PROFILE).
Invoke-Expression (&starship init powershell)

Then nicely disable your omz theme and place a configuration in your ~/.config/starship.toml. Detailed instructions of starship can be found here. It is plausible that you want to change a bunch of default prompt icons from weird emojis into pretty Nerd Fonts, but as Material Design Icons regularly clash with CJK codepoints, personally it is not recommended. Checkout official presets for more configuration ideas.

# Starship config schema
"$schema" = 'https://starship.rs/config-schema.json'

# Example: Inject some prompt of the current operating system
format = "[{windows|linux|vps}](cyan) $all"

Fzf

fzf is an interactive fuzzy finder implemented in Go. By default it will walk the file system as a file finder, but it is capable of finding a whole bunch of other stuff, like searching inside text files, managing Docker environments and picking references from your bibliography. Check the community examples wiki page for some handy inspiration.

Demo

fzf demo

# Use `git` to install
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

Fd

fd is a Rust implementation of GNU find from findutils. It uses regular expressions by default, which is more intuitive than find's verbose parameters. It self proclaims to be even faster than find in its benchmark, as Rust regex automata are fast and the directory traversal part is always carried out in parallel. Beware that fd skips hidden files and gitignore'd files, you need to use the -HI flag to explicitly include them.

Demo

fd demo

fd doesn't come with a install script, so you have to grab them by hand from the release page. Because of name clash, it is called fdfind on apt repo.

Refer to this page for documentation. If you want to use fd to boost your fzf search experience, stuff these env vars into your .zshrc or so.

export FZF_DEFAULT_COMMAND='fd --type file'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"

Ripgrep

This GNU grep alternative is handcrafted by the very author of the Rust regex crate. In fact, the Rust CLI book actually teach you to implement your own grep, but this one, often abbreviated as rg, is technically way more usable. You may want to check the author's blog post for a benchmark. Besides, it provides support for Unicode and basic regex right out of box. If you want to use powerful Perl-flavoured regexes(namely PC2E, with fancy stuff like the (?=foo) lookahead), you can enable the -P flag.

There is also no install script provided, just grab a prebuilt binary from its release page. Beware that rg also skips hidden files and gitignore'd files.

Demo

Bat

Yet another Rust-ified CLI tool from the same author of fd, bat is a human readable version of cat.

cat on a bin

This time, I prefer a cat in my bin than a bat, anyway. But the syntax highlighting and git intergration provided by bat is kind of tempting.

Demo

bat demo: syntax highlighting

bat demo: git

Check this section for its intergration with other fancy CLI apps. Same as fd, grab a binary from the release page, or check batcat(yet another name clash) on apt repo.