How to Build Your Own Command-Line Cheat Sheet System in 30 Minutes with navi

6 views 0 likes 0 comments 19 minutesOriginalTutorial

Tired of endlessly Googling for CLI flags and complex pipelines? This hands-on tutorial walks you through installing, configuring, and customizing `navi`—a powerful interactive terminal cheat sheet tool. In under 30 minutes, you'll build a personalized, searchable, and locally-executable command reference system tailored to your daily workflow.

#command-line # productivity # DevOps # Kubernetes # Docker # cheatsheet # navi # fzf # terminal-tools
How to Build Your Own Command-Line Cheat Sheet System in 30 Minutes with navi

As a backend developer, you've definitely been through moments like these:

  • Trying to rename a container, but completely blanking on whether the Docker volume mount flag is -v or --bind;
  • Scrolling through notes from three months ago just to find that one awk | sed combo for your deployment script;
  • A new teammate asks how a specific git command works, and you awkwardly open Stack Overflow on the spot to look it up...

I've experienced all of these. That was until I discovered navi — an interactive command-line cheat sheet tool with 17k+ stars on GitHub.

In this article, I'll walk you through one specific goal: building your own personalized command-line cheat sheet system from scratch in 30 minutes. By the end, you won't need to memorize commands or waste time searching your browser for syntax you've typed a hundred times. Everything will be local, searchable, and ready to execute with a single keypress.

Let's get started.


Prerequisites

You don't need to know Rust or dive into navi's source code. You just need:

  • A machine running macOS or Linux (Windows users can follow along using WSL2 or Git Bash);
  • Homebrew (macOS) or your preferred package manager; alternatively, having Cargo (Rust's package manager) installed works too;
  • A daily-use shell like bash, zsh, or fish;
  • Basic familiarity with command-line operations (e.g., cd, ls).

Quick tip: Under the hood, navi uses fzf (a fuzzy finder). If you don't have it installed, navi's installer usually handles dependencies automatically. macOS users without Homebrew can grab it by running the official install script first.


The official recommendation is a one-liner via Homebrew:

sh 复制代码
brew install navi

What does this do? Homebrew pulls a pre-compiled navi binary from its community repository, places it in your system PATH, and ensures dependencies like fzf are in place. It's the most hassle-free approach for most developers.

What if you don't use Homebrew? Here are common alternatives:

  • Have Cargo? Run cargo install navi
  • Use SDKMAN, Nix, or similar? navi is also available on Repology (check the project docs for specifics).
  • Want to compile from source? Just clone the repo and run make install, though this is rarely necessary.

Once installed, verify it:

sh 复制代码
navi --version

Seeing a version number means you're ready to go.


Step 2: First Run & Load Community Cheatsheets

Simply type navi in your terminal and hit Enter.

On first launch, navi will prompt you to download community-maintained cheatsheets. These cover dozens of popular tools like git, docker, kubectl, ffmpeg, tmux, and curl. Think of it as a "batteries-included" command dictionary.

Why start with the community repo? It's the fastest way to understand how navi works. The community files use navi's standard format, so once you browse them, you'll intuitively know how to write your own.

After the download finishes, you'll enter an interactive interface: tags appear at the top, and specific commands populate the bottom. Use arrow keys or press / for fuzzy search. Typing docker, for example, instantly filters to all Docker-related entries. Select one and press Enter, and the command will be injected directly into your terminal prompt. Tweak it if needed, then hit Enter to run.


Step 3: Write Your Own Cheatsheet

Community sheets are great, but they're generic. The real power of navi unlocks when you write cheat sheets tailored to your daily workflow.

Cheatsheet files live in ~/.local/share/navi/cheats/ (auto-created on first run). They use the .cheat extension and look like this:

yaml 复制代码
% docker, deployment

## List all running containers
docker ps

## View container logs (last 100 lines)
docker logs --tail 100 -f <container_name_or_id>

$ container_name_or_id: docker ps --format "{{.ID}} {{.Names}}"

Line-by-line breakdown:

  • % docker, deployment defines the tags. Starts with %, followed by comma-separated tag names used for filtering and categorization.
  • # View container... is the description line. Prefixed with #, it acts as a human-readable hint during search.
  • The next line is the actual command to execute.
  • $ container_name_or_id: ... is parameter autocompletion. When you pick this command in navi, it runs the shell command after the colon (here, listing running container IDs and names) and presents a selection list. This is navi's killer feature: you don't need to memorize container IDs; it dynamically fetches them for you.

You can create new .cheat files directly in the cheats/ directory. navi auto-loads them on next launch. Pro tip: keep them organized by tool or scenario, e.g., my-git.cheat, my-deploy.cheat.


Practical Demo: Build Your "Daily Deployment" Cheatsheet

Say you regularly work with Kubernetes and Docker and constantly forget command variants. Let's build a complete example:

  1. Create a new file my-workflow.cheat inside ~/.local/share/navi/cheats/
  2. Paste the following content:
yaml 复制代码
% k8s, deploy

## Check Pod status
kubectl get pods -n <namespace> | grep <app_name>

$ namespace: kubectl get namespaces --no-headers | awk '{print $1}'
$ app_name: kubectl get pods --all-namespaces --no-headers | awk '{print $4}' | sort -u

## Restart a specific Deployment
kubectl rollout restart deployment/<deployment_name> -n <namespace>

$ deployment_name: kubectl get deployments -n <namespace> --no-headers | awk '{print $1}'
$ namespace: kubectl get namespaces --no-headers | awk '{print $1}'

## View last 50 application logs
kubectl logs -n <namespace> deploy/<deployment_name> --tail=50

$ namespace: kubectl get namespaces --no-headers | awk '{print $1}'
$ deployment_name: kubectl get deployments -n <namespace> --no-headers | awk '{print $1}'

Save the file, go back to your terminal, and run navi. Search for the k8s tag, and boom—your three custom commands appear instantly! Pick any one, and navi will prompt you to select the dynamic variables. Once chosen, the final command is ready to execute without ever leaving your terminal.


So far, we've been launching navi manually. But you can make it even smoother by binding it to a shell widget.

For zsh, the official docs provide a straightforward guide to installing shell widgets. Once configured, a simple hotkey (like ALT+C or CTRL+G) instantly pops up navi's search right on your current terminal line. Select a command, and it fills your prompt. You can edit it, then hit Enter. The best part? The full command saves to your shell history, not just navi.

If you use Tmux or work on remote servers, navi also supports a Tmux widget, letting you access cheat sheets seamlessly across any SSH session.

Check the docs/widgets/ directory in the repo for exact configuration steps.


FAQ & Troubleshooting

Q: navi didn't prompt to download community cheatsheets on first run. What now?
Run navi repo browse manually to browse and import them. If you're on a restricted network (e.g., corporate intranet), you can manually clone the cheatsheet repo into ~/.local/share/navi/cheats/repos/.

Q: My custom .cheat file isn't being picked up by navi.
Check that the file encoding is UTF-8 and that tag lines start with % (percent sign followed by a space). Use navi --dry-run to preview parsing results and catch syntax errors.

Q: Parameter autocompletion feels too slow.
Commands after $ execute every time. Large outputs cause delays. Add filters to your autocompletion commands (like using awk to extract exact fields as shown above), or consider caching results.

Q: Can I use it with tldr or cheat.sh?
Yes. navi supports importing tldr and cheat.sh formats. Refer to the docs/cheatsheet/ section in the documentation for migration steps.


Wrap Up

Here's what we accomplished today:

  1. Installed navi via brew install navi
  2. Ran it for the first time, pulled community sheets, and learned fuzzy search & execution
  3. Wrote a custom .cheat file, mastering tags, descriptions, and dynamic parameter autocompletion
  4. Built a real-world K8s/Docker deployment workflow from scratch
  5. Explored shell widget integration for a frictionless terminal experience
  6. Covered common pitfalls to save you debugging time

You now have a fully personalized CLI reference system. Strike while the iron is hot: take the commands you've used this week, compile them into a .cheat file, and search them next time. The efficiency boost will be immediate.

Next steps? Run navi --help to explore subcommands like navi fn and navi best. Try embedding navi in CI/CD scripts, or link it with note-taking apps like TiddlyWiki.

Ultimately, tools are meant to offload the things you shouldn't have to memorize. With navi, save your mental bandwidth for the problems that actually require deep thinking.

Last Updated:

Comments (0)

Post Comment

Loading...
0/500

No comments yet, be the first to comment!