yet.org

Cheat

I’ve been playing with cheatsheets for years, it all started when I studied mathematics. I still have few booklets back from university. I love cheatsheet to tell you the truth, the one thing I love the most is to reduce as much as possible the paper estate taken by information. I have the impression to memorize everything easily when I shrink it. Computers have changed that radically, back when the first programmable calculators appeared on the market, the first digital cheatsheet appeared. It was the beginning of a long story which bring us today to Cheat . A small Python command line program that will be on your side when for god sake you completely forgot the options to block a port using iptables or how to quickly share a file thru HTTP using Python, etc…

It’s maybe not the first time someone release such an utility, you even have the famous man or whereis but most of what’s out there doesn’t give you a quick glimpse of what you really need. It’s too verbose or to terse. Cheat will bring you just enough information at your fingertips and if you don’t find what you’re looking for, don’t hesitate to send a Pull request. It’s only text after all !

Last word before diving in, I’d like to thanks Chris Lane for his contribution.

Installation

You can install cheat directly from PIP (Python Package Manager)

$ sudo pip install cheat

docopt: Pythonic argument parser (installed dependencies)
pygments: syntax highlighting package (installed dependencies).

Pygments can apply syntax highlighting to your cheatsheets, but you need to activate it first with

$ export CHEATCOLORS=true

You can now get a list of cheatsheet

$ cheat -l
7z             /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/7z
ab             /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/ab
apk            /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/apk
apparmor       /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/apparmor
apt-cache      /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/apt-    cache
apt-get        /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/apt-get
aptitude       /usr/local/lib/python2.7/dist-packages/cheat/cheatsheets/aptitude
...

But to make it even more practical, you can activate command completion.

If you’re using zsh you can create a file with the following content and store it somewhere under one of your $fpath directory.

#compdef cheat

declare -a cheats
cheats=$(cheat -l | cut -d' ' -f1)
_arguments "1:cheats:(${cheats})" && return 0

To reload your shell Execute

exec zsh

Note: You’ll find other completion files for bash and fish on github.

Great, now what ?

I’m not going to reproduce here the official docs. So let’s concentrate instead on creating our own cheatsheet. The beauty of cheat is its simplicity. You just have to add another text file in the ~/.cheat directory (by default, or under DEFAULT_CHEAT_DIR).

To give you an example, the Python cheatsheet contains

# Desc: Python is a high-level programming language.

# Basic example of server with python
# Will start a Web Server in the current directory on port 8000
# go to http://127.0.0.1:8000

# Python v2.7
python -m SimpleHTTPServer
# Python 3
python -m http.server 8000

# SMTP-Server for debugging, messages will be discarded, and printed on stdout.
python -m smtpd -n -c DebuggingServer localhost:1025

# Pretty print a json
python -mjson.tool

It’s that easy.

Imagine now you forgot even the name of the command to compress files, just search in the cheatsheet for keywords :

cheat -s compress

If you don’t know Python well, looking at the source code will also give you a quick idea about the language.

I hope Chris Lane simple idea will resonate and that you’ll fork and Pull Request to contribute.

The more cheats the better.