––» HOME «––

cheat.sh
using cheat.sh in your shell :)

Table of Contents

1. what is cheat.sh?

cheat.sh is a wonderful online cheat-sheet archive. You can use it with curl from your commandline.

$ curl cheat.sh
      _                _         _    __
  ___| |__   ___  __ _| |_   ___| |__ \ \      The only cheat sheet you need
 / __| '_ \ / _ \/ _` | __| / __| '_ \ \ \     Unified access to the best
| (__| | | |  __/ (_| | |_ _\__ \ | | |/ /     community driven documentation
 \___|_| |_|\___|\__,_|\__(_)___/_| |_/_/      repositories of the world

+------------------------+ +------------------------+ +------------------------+
| $ curl cheat.sh/ls     | | $ cht.sh btrfs         | | $ cht.sh lua/:learn    |
| $ curl cht.sh/btrfs    | | $ cht.sh tar~list      | | Learn any* programming |
| $ curl cht.sh/tar~list | |                        | | language not leaving   |
| $ curl https://cht.sh  | |                        | | your shell             |
|                        | |                        | | *) any of 60           |
|                        | |                        | |                        |
+-- queries with curl ---+ +- own optional client --+ +- learn, learn, learn! -+
+------------------------+ +------------------------+ +------------------------+
| $ cht.sh go/f<tab><tab>| | $ cht.sh --shell       | | $ cht.sh go zip lists  |
| go/for   go/func       | | cht.sh> help           | | Ask any question using |
| $ cht.sh go/for        | | ...                    | | cht.sh or curl cht.sh: |
| ...                    | |                        | | /go/zip+lists          |
|                        | |                        | | (use /,+ when curling) |
|                        | |                        | |                        |
+---- TAB-completion ----+ +-- interactive shell ---+ +- programming questions-+
+------------------------+ +------------------------+ +------------------------+
| $ curl cht.sh/:help    | | $ vim prg.py           | | $ time curl cht.sh/    |
| see /:help and /:intro | | ...                    | | ...                    |
| for usage information  | | zip lists _            | | real    0m0.075s       |
| and README.md on GitHub| | <leader>KK             | |                        |
| for the details        | |             *awesome*  | |                        |
|            *start here*| |                        | |                        |
+--- self-documented ----+ +- queries from editor! -+ +---- instant answers ---+

[Follow @igor_chubin for updates][github.com/chubin/cheat.sh]

2. How to use it?

And it's very useful if you're using the commandline very often. You can put a tag in the URL like this:

$ curl cheat.sh/if
# if
# Simple shell conditional.

# Echo a different thing depending on a command's success:
command && echo "success" || echo "failure"

# Full if syntax:
if condition; then echo "true"; else echo "false"; fi

# List available if conditions:
help test

# Test if a given variable is empty:
if [[ -z $GIT_BRANCH ]]; then echo "true"; else echo "false"; fi

# Test if a file exists:
if [[ -e filename ]]; then echo "true"; else echo "false"; fi

# If directory not exists:
if [[ ! -d path/to/directory ]]; then echo "true"; else echo "false"; fi

…and it gives you the most common useage examples. Which is exactly what you want in most situations, I guess.

2.1. Script usage

I made mysself a little script so it asks me what to search if I don't give it an argument. It looks like this:

$ cat scripts/cheat.sh
#! /bin/bash

if [ $1 ];
  then curl cheat.sh/$1;
else
  echo -e "\033[32m  --> \033[33mworüber willst du etwas wissen?\033[0m";
  read -r what;
  curl cheat.sh/$what;
fi

The ugly looking \033[33m stuff is only coloring - never mind that :) If I give an argument it looks up cheat.sh with that argument. If not it asks me what I want to search. Like this (with an argument):

$ cheat case
# case
# Branch based on the value of an expression.

# Match a variable against string literals to decide which command to run:
case $tocount in words) wc -w README; ;; lines) wc -l README; ;; esac

# Combine patterns with |, use * as a fallback pattern:
case $tocount in [wW]|words) wc -w README; ;; [lL]|lines) wc -l README; ;; *) echo "what?"; ;; esac

or this (without an argument):

cheat
--> worüber willst du etwas wissen?
at
cheat:at
# To schedule a one time task
at {time}
{command 0}
{command 1}
Ctrl-d

# {time} can be either
now | midnight | noon | teatime (4pm)
HH:MM
now + N {minutes | hours | days | weeks}
MM/DD/YY

# To list pending jobs
atq

# To remove a job (use id from atq)
atrm {id}

tldr:at
# at
# Execute commands once at a later time.
# Service atd (or atrun) should be running for the actual executions.

# Execute commands from standard input in 5 minutes (press `Ctrl + D` when done):
at now + 5 minutes

# Execute a command from standard input at 10:00 AM today:
echo "./make_db_backup.sh" | at 1000

# Execute commands from a given file next Tuesday:
at -f path/to/file 9:30 PM Tue

To make it work like this i also aliased cheat to the script like this:

cat .bash_aliases | grep cheat
alias cheat="$HOME/scripts/cheat.sh"

Works like a charme, to me :D Maybe you wanna give it a try…

Date: 2021-08-16 Mo 13:37