cheat, examples for CLIs

CLIs are very powerful, from the tip of fingers, you can quickly make the computer do anything you want. No need to wave your mouse around, hoping to find the right sub-sub-sub-menu where the feature you want is implemented.

But it comes at a cost: for each command, you need to know how to write its arguments, what are the existing flags, what does it need from stdin/stdout, and so on. Of course, you can read its manpage, scrolling through pages of explanation on the internals and what language is accepted by the newly added LL(1) parser, which still has some issues but tries to keep compatibility with …
It’s a trade-off between having to know these and speed. Let’s face it, when you know pretty much a tool but aren’t sure of the syntax, you only need the examples section.

Here comes cheat, a command to show cheatsheets for many commonly used CLIs. So, for example, you started a screen previously on a server, and when relogin on it, you want to reattach but don’t know the options. You can simply cheat screen and it outputs

# To start a new named screen session:
screen -S <session-name>
# To detach from the current session:
Press Ctrl+A then press d
# To re-attach a detached session:
screen -r <session-name>
# To list all screen sessions:
screen -ls

Now, you know how to first find your old session (don’t lie, you’d have tabbed and hope to land on the right one) and how to reattach to it, even how to leave it! If you don’t find what you’re looking for, you can read the man page and you can then cheat -e <tool> to add your findings to your own personal cheatsheet. There is even support for a local .cheat directory, so you can have some project specific cheats.