Install Cheat Command on Ubuntu 20.04

0
608

In this tutorial, you will learn how to install cheat command on Ubuntu 20.04. Cheat is a Python based command line utility that allows you to create and view interactive cheat sheets on the command-line. It was designed to help remind *nix system administrators of options for commands that they use frequently, but not frequently enough to remember.

Install Cheat Command on Ubuntu 20.04

To install cheat command on Ubuntu 20.04, step through this guide as follows.

Run System Update

Update your system package cache;

sudo apt update

Install Python PIP on Ubuntu 20.04

Cheat is Python based program. As such, its installation has to be done through the use the Python package manager, PIP. Install Python pip on Ubuntu 20.04 by executing the command below;

sudo apt install python3-pip

Install Cheat Command on Ubuntu 20.04

Once Python package manager is installed, you can then install cheat command on Ubuntu 20.04 by running the command below;

sudo pip3 install cheat
Collecting cheat
  Downloading cheat-2.5.1.tar.gz (82 kB)
     |████████████████████████████████| 82 kB 243 kB/s 
Collecting docopt>=0.6.1
  Downloading docopt-0.6.2.tar.gz (25 kB)
Collecting pygments>=1.6.0
  Downloading Pygments-2.7.2-py3-none-any.whl (948 kB)
     |████████████████████████████████| 948 kB 403 kB/s 
Collecting termcolor>=1.1.0
  Downloading termcolor-1.1.0.tar.gz (3.9 kB)
Building wheels for collected packages: cheat, docopt, termcolor
  Building wheel for cheat (setup.py) ... done
  Created wheel for cheat: filename=cheat-2.5.1-py3-none-any.whl size=107856 sha256=1ae35293a86ace4491b98c4ec772372fb65cdd6da9407031f953e5f9483d37b1
  Stored in directory: /root/.cache/pip/wheels/a6/2d/b2/8bd4534364edd5c6940fc495d595d949a2310e982e89865e95
  Building wheel for docopt (setup.py) ... done
  Created wheel for docopt: filename=docopt-0.6.2-py2.py3-none-any.whl size=13704 sha256=dd271e68af7385449d4560461bc4136f01ba7f869e63e3a48d3cad21bd209db5
  Stored in directory: /root/.cache/pip/wheels/56/ea/58/ead137b087d9e326852a851351d1debf4ada529b6ac0ec4e8c
  Building wheel for termcolor (setup.py) ... done
  Created wheel for termcolor: filename=termcolor-1.1.0-py3-none-any.whl size=4830 sha256=2d9d7fe0ba735b776c423aab78232847c5a219a3d54833938440ebf3241b8de0
  Stored in directory: /root/.cache/pip/wheels/a0/16/9c/5473df82468f958445479c59e784896fa24f4a5fc024b0f501
Successfully built cheat docopt termcolor
Installing collected packages: docopt, pygments, termcolor, cheat
Successfully installed cheat-2.5.1 docopt-0.6.2 pygments-2.7.2 termcolor-1.1.0

Cheat is now installed successfully on Ubuntu 20.04;

cheat -v
cheat 2.5.1

Set Default Cheat Text Editor

Once the installation is done, you need to define the default text editor for your cheat program. By default, Cheat used the editor defined by the EDITOR environment variable.

For example, to check what value is assigned to the EDITOR environment variable;

echo $EDITOR
/usr/bin/vim

Or;

printenv EDITOR

If the EDITOR environment variable has not been assigned any editor, you can simply assign it. For example, if you want to use vim editor as your default text editor, run the command;

export EDITOR=`which vim`

When you run cheat command, it should now use vim editor to manage your cheatsheets.

To permanently set your EDITOR environment variable, you can enter the line above into the ~/.bashrc or ~/.zshrc file depending to the shell you are using;

echo "export EDITOR=which vim" >> ~/.bashrc
source ~/.bashrc

or

echo "export EDITOR=which vim" >> ~/.zshrc
source ~/.zshrc

Set Cheat Default Cheatsheets Directory

By default, cheatsheets are stored under, $HOME/.cheat/ directory. If you want to store your cheats in a different directory, you need to set the directory as the value for the DEFAULT_CHEAT_DIR.

export DEFAULT_CHEAT_DIR=$HOME/Documents/cheats

This sets the default directory for the cheats to $HOME/Documents/cheats.

You can permanently set this in ~/.zshrc or ~/.bashrc.

Cheat Command Usage

To see how to use cheat command;

cheat --help
Usage:
  cheat <cheatsheet>
  cheat -e <cheatsheet>
  cheat -s <keyword>
  cheat -l
  cheat -d
  cheat -v

Options:
  -d --directories  List directories on $CHEAT_PATH
  -e --edit         Edit cheatsheet
  -l --list         List cheatsheets
  -s --search       Search cheatsheets for <keyword>
  -v --version      Print the version number

Example Usage of Cheat command

To view a cheatsheet:

cheat tar      # a "top-level" cheatsheet
cheat foo/bar  # a "nested" cheatsheet

To edit a cheatsheet:

cheat -e tar     # opens the "tar" cheatsheet for editing, or creates it if it does not exist
cheat -e foo/bar # nested cheatsheets are accessed like this

To view the configured cheatpaths:

cheat -d

To list all available cheatsheets:

cheat -l

To list all cheatsheets that are tagged with “networking”:

cheat -l -t networking

To list all cheatsheets on the “personal” path:

cheat -l -p personal

To search for the phrase “ssh” among cheatsheets:

cheat -s ssh

To search (by regex) for cheatsheets that contain an IP address:

cheat -r -s '(?:[0-9]{1,3}\.){3}[0-9]{1,3}'

Flags may be combined in intuitive ways. Example: to search sheets on the “personal” cheatpath that are tagged with “networking” and match a regex:

cheat -p personal -t networking --regex -s '(?:[0-9]{1,3}\.){3}[0-9]{1,3}'

And that marks the end of our tutorial on how to install cheat command on Ubuntu 20.04.

Reference

Github cheat/cheatsheets

Other Tutorials

Create User Account using useradd/adduser commands in Linux

Install and Setup ZSH and Oh-My-Zsh on Ubuntu 20.04

Installing Perf Performance Analysis Tool on CentOS 8

Run only Specific Commands with sudo in Linux

LEAVE A REPLY

Please enter your comment!
Please enter your name here