Cheat.sh displays cheat sheet in command line or code editor

cheat Use a variety of interfaces to provide community-driven cheat sheets and summaries of Linux / UNIX commands and many programming languages. It can be used in a web browser from the command line (using curl or Linux or Windows-specific command line client) in a web browser and as a plugin for Vim, Emacs, Visual Studio Code, Sublime Text and IntelliJ Idea, So you can search and insert code snippets without leaving the code editor / command line.
For cheat sheets, the tool leverages community-driven source Like TLDR page, Learn X in Y minutes, StackOverflow, etc., as well as its own repository.
Although it also has its own cheat sheet repository, the project actually focused on creating a unified mechanism to access a well-maintained cheat sheet repository.
The tool was developed by Igor Chubin, who is also known for his console-oriented weather forecast service weightCan be used to retrieve the weather from the console using only cURL or Wget.
It’s worth noting that cheat.sh is not new. In fact, it was first submitted around May 2017 and is a very popular repository on GitHub. But I personally only discovered it recently, so I found it very useful, so I think there must be some Linux Uprising readers who don’t know this is cool.

cheat.sh features and more

cheat.sh tar example

cheat.sh main functions:

  • Support 58 Programming language, Several DBMS and more than 1000 most important UNIX / Linux commands
  • Very fast, returns the answer in 100 milliseconds
  • Simple curl / browser interface
  • An optional command line client (cht.sh) is available, which allows you to quickly search cheat sheets and easily copy code snippets without leaving the terminal
  • Can be used from a code editor, search for code snippets without having to insert a web browser, search for code, copy the code, then return to the code editor and paste. It supports Vim, Emacs, Visual Studio Code, Sublime Text and IntelliJ Idea
  • Comes with a special stealth mode where any text you select (add it to the X Window System’s selection buffer or clipboard) is used as a search query for cht.sh, so you don’t need to touch any other keys to get answer

The command line client has a special shell mode with persistent query context and readline support. It also has query history, integrates with the clipboard, supports tab completion for shells like Bash, Fish, and Zsh, and includes the stealth mode I mentioned in cheat.sh feature.
Web, curl and cht.sh (command line) interfaces are used https://cheat.sh/ But if you want, you can Self-hosting it.
It should be noted that each editor plugin supports a different feature set (configurable server, multiple answers, switching comments, etc.). You can check the feature comparison of each cheat.sh editor plugin on it. Editorial integration The project’s GitHub page“. See the cheat.sh guide on Edit or add New cheat sheet. Interested in bookmark commands? You might want to try Marker (the console’s command bookmark manager).

cheat.sh curl / command line client usage example

Example using cheat.sh using the curl interface from the command line (this requires curl to be installed as expected):
Show tar Order cheat sheet:

curl cheat.sh/tar

Example output:

$ curl cheat.sh/tar
# To extract an uncompressed archive:
tar -xvf /path/to/foo.tar

# To create an uncompressed archive:
tar -cvf /path/to/foo.tar /path/to/foo/

# To extract a .gz archive:
tar -xzvf /path/to/foo.tgz

# To create a .gz archive:
tar -czvf /path/to/foo.tgz /path/to/foo/

# To list the content of an .gz archive:
tar -ztvf /path/to/foo.tgz

# To extract a .bz2 archive:
tar -xjvf /path/to/foo.tgz

# To create a .bz2 archive:
tar -cjvf /path/to/foo.tgz /path/to/foo/

# To extract a .tar in specified Directory:
tar -xvf /path/to/foo.tar -C /path/to/destination/

# To list the content of an .bz2 archive:
tar -jtvf /path/to/foo.tgz

# To create a .gz archive and exclude all jpg,gif,... from the tgz
tar czvf /path/to/foo.tgz --exclude=*.{jpg,gif,png,wmv,flv,tar.gz,zip} /path/to/foo/

# To use parallel (multi-threaded) implementation of compression algorithms:
tar -z ... -> tar -Ipigz ...
tar -j ... -> tar -Ipbzip2 ...
tar -J ... -> tar -Ipixz ...

cht.sh can also replace cheat.sh:

curl cht.sh/tar

Want to search for one keyword In all cheat sheets? use:

curl cheat.sh/~keyword

A Python programming language cheat sheet listing the following random list:

curl cht.sh/python/random+list

Example output:

$ curl cht.sh/python/random+list
#  python - How to randomly select an item from a list?
#  
#  Use random.choice
#  (https://docs.python.org/2/library/random.htmlrandom.choice):

import random

foo = ['a', 'b', 'c', 'd', 'e']
print(random.choice(foo))

#  For cryptographically secure random choices (e.g. for generating a
#  passphrase from a wordlist), use random.SystemRandom
#  (https://docs.python.org/2/library/random.htmlrandom.SystemRandom)
#  class:

import random

foo = ['battery', 'correct', 'horse', 'staple']
secure_random = random.SystemRandom()
print(secure_random.choice(foo))

#  [Pēteris Caune] [so/q/306400] [cc by-sa 3.0]

Replace python Works with other programming languages ​​supported by cheat.sh, and random+list The cheat sheet to display.
Do you want to delete the comment in the answer? Add ?Q At the end of the query (below is an example using the same / python / random + list):

$ curl cht.sh/python/random+list?Q
import random

foo = ['a', 'b', 'c', 'd', 'e']
print(random.choice(foo))

import random

foo = ['battery', 'correct', 'horse', 'staple']
secure_random = random.SystemRandom()
print(secure_random.choice(foo))

For more flexibility and tab completion, you can use cht.sh (command-line cheat.sh client). You will find instructions on how to install it later in this article. Example using cht.sh command line client:
Show tar Order cheat sheet:

cht.sh tar

A Python programming language cheat sheet listing the following random list:

cht.sh python random list

No need to use quotes with multiple keywords.
You can start the cht.sh client using the following special shell modes:

cht.sh --shell

You can then start typing the query. example:

$ cht.sh --shell
cht.sh> bash loop

If all queries are for the same programming language, the client can be launched directly in that context in a special shell mode. For example, start it in a Bash context using the following command:

cht.sh --shell bash

Example output:

$ cht.sh --shell bash
cht.sh/bash> loop
...........
cht.sh/bash> switch case

Do you want to copy the previously listed answers to the clipboard? Types of c,then press Enter Copy the entire answer, or type C then press Enter Copy it without commenting.
Types of help View all available commands in cht.sh interactive shell mode. Also look Use part Get more options and advanced usage from the cheat.sh GitHub project page.

How to install the cht.sh command line client

You can use cheat.sh in a web browser with the help of curl’s command line, without having to install other code editor plugins (as described above), or install anything else, or use its command line client (with some Extra features), I have already mentioned. The following steps are used to install this cht.sh command line client.
If you want to install a code editor plugin for cheat.sh, see Editorial integration Install dependencies on page 1.
To install the cht.sh command line client: curl You will use the command line tool, so you need to install it on your system. Another dependency is rlwrapThis is required for cht.sh special shell mode. Install these dependencies as follows.

  • Debian, Ubuntu, Linux Mint, Pop! _OS and any other Debian or Ubuntu based Linux distribution:
sudo apt install curl rlwrap
  • Fedora:
sudo dnf install curl rlwrap
  • Arch Linux, Manjaro:
sudo pacman -S curl rlwrap
  • openSUSE:
sudo zypper install curl rlwrap

In most, if not all, Linux distributions, these packages appear to have the same name, so if your Linux distribution is not on this list, just install curl with rlwrap Package package 2 using the release’s package manager. Download and install cht.sh command line interface.
You can install this file only for your users (so only you can run it) or all users:

  • Install only for your users. The following command assumes you have a ~/.bin Folder added to your PATH (And the folder exists). If your other local folders PATH Where to install cht.sh, change the installation path in the command:
curl https://cht.sh/:cht.sh > ~/.bin/cht.sh

chmod +x ~/.bin/cht.sh
  • Install for all users (Global /usr/local/bin):
curl https://cht.sh/:cht.sh | sudo tee /usr/local/bin/cht.sh

sudo chmod +x /usr/local/bin/cht.sh

If the first command seems to freeze and only shows the cURL output, press Enter Key and you will be prompted for a password to save the file to /usr/local/binYou can also download and install the cheat.sh command for Bash or Zsh to complete:

  • Slam:
mkdir ~/.bash.d

curl https://cheat.sh/:bash_completion > ~/.bash.d/cht.sh

echo ". ~/.bash.d/cht.sh" >> ~/.bashrc
  • Zsh:
mkdir ~/.zsh.d

curl https://cheat.sh/:zsh > ~/.zsh.d/_cht

echo 'fpath=(~/.zsh.d/ $fpath)' >> ~/.zshrc

Open a new shell / terminal and it will load cheat.sh to finish.

Source

Sidebar