Cheat sheets for the shell

Interactive Cheat Sheet

© Lead Image © Stanislav Volchenkov, 123RF

© Lead Image © Stanislav Volchenkov, 123RF

Article from Issue 234/2020
Author(s):

When the history function fails and the manpage is too long, navi comes to the rescue with an interactive cheat sheet for the shell.

What exactly was that parameter for creating an archive with tar? Command-line aficionados know that if nothing shows up with the Bash history command, your only option is to look at the manpage. While manpages are generally useful, some are so extensive that the time spent searching for information is disproportionate to the task at hand. An alternative to this problem is an interactive cheat sheet.

While there are plenty of cheat sheet tools on GitHub, the relatively young navi [1] offers both good functionality and an eye-pleasing design. Navi helps users browse built-in (DIY or downloaded) cheat sheets to display options and arguments for commands or directly execute the commands. Navi (as well as similar tools) lets you interactively learn about newly discovered commands and explore all their possibilities.

Installation

You can quickly install navi from the website (Listing 1). In addition, you can optionally install navi in an arbitrary directory (line 6) instead of in your path.

Listing 1

Installing navi

01 $ sudo git clone --depth 1 https://github.com/denisidoro/navi /opt/navi
02 $ cd /opt/navi
03 ### Install in $PATH
04 $ sudo make install
05 ### Alternatively
06 $ ./scripts/install <directory>

Navi does have a couple of dependencies. To avoid having navi complain, you must install the fzf string matching algorithm, a search tool that uses fuzzy searches to quickly find specific strings in a longer string or text.

You can find fzf in the Debian, Fedora, and Arch Linux repositories, where you can install it with the standard package manager. Alternatively, Mac OS X users can use Homebrew [2] for the installation. For Z shell [3] users, navi's developer offers a guide for integrating the widely used Oh My ZSH [4] configuration file.

Navi's only other dependency is ncurses, which should be preinstalled on every distribution.

Since work on the relatively young navi is ongoing, you will want to update the software regularly. When a new version appears on GitHub, you can update navi quickly with git (Listing 2).

Listing 2

Updating navi

$ cd "$(navi home)"
$ sudo git pull

Getting Started

First, you will want to briefly familiarize yourself with navi's arguments and options by calling navi --help in a shell. Then start the program by entering navi. Navi opens a current list of 242 embedded cheat sheets (Figure 1).

Figure 1: Navi displays the current list of cheat sheets at startup.

In the three-part view in Figure 1, you can see the application or environment from which the commands originate on the left, the tasks to be performed with them in the middle, and the corresponding command on the right. You can choose to limit the display of commands to one category. For example,

navi query git

only shows commands for git. Alternatively, you can narrow down the results in the window by typing ip addr, which results in the three commands that deal with IP addresses (Figure 2).

Figure 2: Keywords are used to limit the commands to a specific topic directly in the window.

Direct Execution

Navi's interactivity comes into play when you double-click on a selected command. If the command requires no further input, the program passes it directly to the shell. For instance, clicking on the List running services task from the systemctl, service category takes you directly to a list of running services (Figure 3). In this example, direct execution of the command does not pose a problem, because the command only prints a list and makes no other changes to your system.

Figure 3: Commands that do not change the system (e.g., listing active services) can be executed directly without any risk.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Cheat: Cheatsheets for Command-Line Tools
  • FOSSPicks

    Like tardy London buses, Graham has waited months for a decent open source instant messenger client to arrive, and then in this month's FOSSPicks, he found two. Perfect for staying in touch with friends and family from the comfort of your own sofa.

  • The sys admin's daily grind: cheat.sh

    Whenever you really need documentation, it's almost always incomplete or outdated – or both. Sys admin columnist Charly K¸hnast recommends a radically different approach: the universal community documentation cheat.sh, which no Linux command and hardly any programming language should do without.

  • Digital Forensics and Incident Response

    When it's too late to stop an attack, the next urgent task is to find out what happened and assess the damage.

  • Cheat Sheet

    A simplified alternative to man pages, tldr provides the most common command options at a glance.

comments powered by Disqus