Cheat.sh, documentation for the command line or for your editor

about cheat.sh

In the next article we are going to take a look at cheat.sh. This script will provide us with access to documentation and code snippets Community-driven, for Linux / UNIX commands and many programming languages. This project is not new, it started in 2017, but it is still very useful for many users.

To display its content, the tool makes use of sources community driven such as TLDR pages, StackOverflow and others, as well as its own repository. We will be able to use this utility from the web browser, the command line or as a complement for Vim, Emacs or Sublime Text, among other editors.

This tool has been developed by Igor Chubin, also known for its console-oriented weather forecast service called wttr.in.

General features of Cheat.sh

  • We could do queries on 58 programming languages, various DBMS and 1000 of the most important UNIX / Linux commands.
  • Un client for optional command line (cht.sh) is available. This will allow us to quickly search and copy code snippets easily without leaving the terminal.
  • The web and cht.sh (command line) interfaces use cheat.sh, but if the user prefers, they can self host it.
  • The command line client presents a special shell mode with a persistent query context. It also has a query history that is integrated with the clipboard. At the same time it supports tab completion for shells like Bash, Fish and Zsh.
  • Offer psychological therapy to employees results very fast. Returns responses in less than 100 ms.
  • The utility can be used from code editors. This will allow us insert code snippets without having to open a web browser, find the code, copy it, and then go back to the code editor to paste it. It is compatible with Vim, Emacs, Visual Studio Code, Sublime Text, and IntelliJ Idea.

If someone is encouraged, they can contribute to the project. You can consult the cheat.sh guide to edit or add content.

How to install the cht.sh command line client

We will be able to use cheat.sh in a web browser, from the command line with the help of curl without having to install anything else, as a code editor plugin or using its command line client.

If you want to install it as a complement to a code editor, you can consult the page for integration in editors.

Next we will see the necessary steps to install this command line client called cht.sh, but first we will have to solve the issue of dependencies.

Install dependencies

In order to install the cht.sh command line client, we will use curl. Another dependency is rlwrap, which is required by the special shell mode cht.sh. In Debian, Ubuntu, Linux Mint and any other Gnu / Linux distribution based on Debian or Ubuntu, we will write in the terminal (Ctrl + Alt + T):

install dependencies

sudo apt install curl rlwrap

Download and install the cht.sh command line interface

We can install it only for one user or for all users. You can install it for all users using the folder / usr / local / bin:

cht.sh curl

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 have frozen and shows only the CURL output, press the Enter key. It will ask you to enter your password to save the file in / usr / local / bin.

If you want to install it only for your user we will assume that you have a folder ~ / .bin added to your PATH and the folder exists. You can change this folder to your liking. Depending on where you want to install cht.sh, change the installation path in the commands:

curl https://cht.sh/:cht.sh > ~/.bin/cht.sh

chmod +x ~/.bin/cht.sh

Customer usage examples

Next we will see some cheat.sh usage examples using curl from the command line:

To display the some options available for the command ls:

cheat.sh ls

curl cheat.sh/ls

Cht.sh also works instead of cheat.sh:

cht.sh ls

curl cht.sh/ls

To see an example of the rand () function for the PHP programming language we will write:

rand php function

curl cht.sh/php/rand

If you want to delete the comments that will be seen in the result, you will have to add? Q at the end of the query:

rand php no comments

curl cht.sh/php/rand?Q

We will be able start the cht.sh client in a special shell mode using:

cht.sh --shell

cht.sh --shell

Then we can start writing our queries. To close, you just have to write exit.

cht --help

If we write help in the interactive shell cht.sh mode, we will be able to see all the available possibilities. You can also search the Usage section from the cheat.sh project page on GitHub to see the options it offers us.


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

Be the first to comment

Leave a Comment

Your email address will not be published.

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.