The commands I use daily (git, ls, cd, grep) are burned into muscle memory. But the ones I reach for once every three months? Like that specific ffmpeg incantation to trim a video, or the exact du flags to get human-readable disk usage sorted by size. I would always end up on Google (or, more recently, asking the AI) just to get the flags right.
A few years ago I stumbled upon navi. It is an interactive cheatsheet tool for the command line, written in Rust. You write your own cheat files and navi shows them through fzf, letting you fuzzy-find the command you need. It also supports variables, so you can template commands and fill in the blanks interactively.
The project sits at 17k+ stars on GitHub. It needs fzf (or skim as an alternative) and is available on Arch through pacman -S navi, but I prefer to install it via cargo since I already have the Rust toolchain.
Here you can see it in action: https://asciinema.org/a/406461
Here you can find my own cheatsheets, collected through the years: https://github.com/tiagoprn/devops/tree/master/cheats (the *.cheat files are used my navi, the other folders I use with another tool named “television”).
And below is how I set it up.
fzf installed on your systemrustup and cargo installedCheck if you have fzf:
fzf --version
If not, install it. On Arch-based distros:
sudo pacman -S fzf
On Debian/Ubuntu:
sudo apt install fzf
The easiest way to keep navi updated is through cargo:
cargo install navi
This compiles from source and puts the binary at ~/.cargo/bin/navi. Make sure that directory is in your PATH:
# Add this to ~/.bashrc or ~/.zshrc if not already there
export PATH="$HOME/.cargo/bin:$PATH"
Navi uses .cheat files. The syntax is straightforward. Create a directory:
mkdir -p ~/.config/navi/cheats
Then create a file, say ~/.config/navi/cheats/utils.cheat:
% disk, storage
# Show disk usage in human-readable format, sorted by size
du -sh <dir> | sort -h
# Show disk usage of top-level directories only
du -sh -- */ | sort -h
The % line defines the category (used for filtering). Lines starting with # describe the command. The bare lines below are the actual commands. Things like <dir> become text inputs when you select the command.
The real power is binding navi to a keyboard shortcut. I use Ctrl+G. Add this to your ~/.bashrc:
# NOTE: below enables using 'CTRL+G' to call navi in INSERT MODE
# and make its' commands to appear on the shell history:
# https://github.com/denisidoro/navi/issues/462
export NAVI_PATH="$NAVI_PATH:/storage/src/devops/cheats:/here/is/another/folder/with/cheatsheets"
eval "$(navi widget bash)"
Now when I press Ctrl+G, navi opens. I start typing to filter, pick the command, fill in the blanks, and the full command lands on my prompt.
# Navi should be available
navi --version
# Open navi interactively (press Ctrl+G or run)
navi
# Check that cargo installed it
which navi
When you run navi or press Ctrl+G, you get a fuzzy search interface. Type to filter, select, and the command appears on your terminal ready to run.
$ dir: find /home -maxdepth 1 -type d would let you pick from actual directories.skim instead of fzf, pass --fzf-override skim or set it as your default.--print flag used in the keybinding above makes navi output the command to stdout instead of executing it directly.