Let's imagine for a moment that there is such a thing as an ideal cheat sheet. What should it look like? What features should it have? Show
Such a thing exists! It's easy to and there's even . Featurescheat.sh
ContentsUsageTo get a cheat sheet for a UNIX/Linux command from a command line, query the service using 9 or any other HTTP/HTTPS client specifying the name of the command in the query:
As you can see, you can use both HTTPS and HTTP to access the service, and both the long (cheat.sh) and the short (cht.sh) service names. Here 0, 9, 2, and 3 are names of the UNIX/Linux commands you want to get cheat sheets for.If you don't know the name of the command you need, you can search for it using the 4 notation. For example, to see how you can make 5 of a filesystem/volume/something else:
The programming language cheat sheets are located in special namespaces dedicated to them.
To get the list of available programming language cheat sheets, use the special query 6:
Almost each programming language has a special page named 7 that describes the language basics (that's a direct mapping from the "Learn X in Y" project). It could be a good starting point if you've just started learning a language.If there is no cheat sheet for a programming language query (and it is almost always the case), it is generated on the fly, based on available cheat sheets and answers on StackOverflow. Of course, there is no guarantee that the returned cheat sheet will be a 100% hit, but it is almost always exactly what you are looking for. Try these (and your own) queries to get the impression of that, what the answers look like:
If you don't like an answer for your queries, you can pick another one. For that, repeat the query with an additional parameter 8, 9 etc. appended:
Cheat sheets are formatted as code of the queried programming language (at least we are trying our best to do so) so they can be pasted into a program in this language directly. Text comments, if there are any, are formatted according to the language syntax. $ curl cht.sh/lua/table+keys -- lua: retrieve list of keys in a table local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end --[[ [ Note that you cannot guarantee any order in keyset. If you want the [ keys in sorted order, then sort keyset with table.sort(keyset). [ [ [lhf] [so/q/12674345] [cc by-sa 3.0] ]] If you don't need text comments in the answer, you can eliminate them using a special option 0:$ curl cht.sh/lua/table+keys\?Q local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end And if you don't need syntax highlighting, switch it off using 1. You can combine the options together:
Full list of all options described below and in 2.Try your own queries. Follow these rules:
Read more about the programming languages queries below. Command line client, cht.shThe cheat.sh service has its own command line client ( 8) that has several useful features compared to querying the service directly with 9:
InstallationTo install the client: PATH_DIR="$HOME/bin" # or another directory on your $PATH mkdir -p "$PATH_DIR" curl https://cht.sh/:cht.sh > "$PATH_DIR/cht.sh" chmod +x "$PATH_DIR/cht.sh" or to install it globally (for all users): 0Note: The package "rlwrap" is a required dependency to run in shell mode. Install this using $ curl cht.sh/lua/table+keys -- lua: retrieve list of keys in a table local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end --[[ [ Note that you cannot guarantee any order in keyset. If you want the [ keys in sorted order, then sort keyset with table.sort(keyset). [ [ [lhf] [so/q/12674345] [cc by-sa 3.0] ]]1 Client usageNow, you can use 8 instead of 9, and write your queries in more natural way, with spaces instead of 6: 1It is even more convenient to start the client in a special shell mode: 2If all your queries are about the same language, you can change the context and spare repeating the programming language name: 3or even start the client in this context: 4If you want to change the context, you can do it with the $ curl cht.sh/lua/table+keys -- lua: retrieve list of keys in a table local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end --[[ [ Note that you cannot guarantee any order in keyset. If you want the [ keys in sorted order, then sort keyset with table.sort(keyset). [ [ [lhf] [so/q/12674345] [cc by-sa 3.0] ]]5 command, or if you want do a single query for some other language, just prepend it with $ curl cht.sh/lua/table+keys -- lua: retrieve list of keys in a table local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end --[[ [ Note that you cannot guarantee any order in keyset. If you want the [ keys in sorted order, then sort keyset with table.sort(keyset). [ [ [lhf] [so/q/12674345] [cc by-sa 3.0] ]]6: 5If you want to copy the last answer into the clipboard, you can use the $ curl cht.sh/lua/table+keys -- lua: retrieve list of keys in a table local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end --[[ [ Note that you cannot guarantee any order in keyset. If you want the [ keys in sorted order, then sort keyset with table.sort(keyset). [ [ [lhf] [so/q/12674345] [cc by-sa 3.0] ]]7 ( $ curl cht.sh/lua/table+keys -- lua: retrieve list of keys in a table local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end --[[ [ Note that you cannot guarantee any order in keyset. If you want the [ keys in sorted order, then sort keyset with table.sort(keyset). [ [ [lhf] [so/q/12674345] [cc by-sa 3.0] ]]8) command, or $ curl cht.sh/lua/table+keys -- lua: retrieve list of keys in a table local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end --[[ [ Note that you cannot guarantee any order in keyset. If you want the [ keys in sorted order, then sort keyset with table.sort(keyset). [ [ [lhf] [so/q/12674345] [cc by-sa 3.0] ]]9 ( $ curl cht.sh/lua/table+keys\?Q local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end0, without comments). 6Type $ curl cht.sh/lua/table+keys\?Q local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end1 for other internal 8 commands. 7The 8 client has its configuration file which is located at $ curl cht.sh/lua/table+keys\?Q local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end4 (location of the file can be overridden by the environment variable $ curl cht.sh/lua/table+keys\?Q local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end5). Use it to specify query options that you would use with each query. For example, to switch syntax highlighting off create the file with the following content: 8Or if you want to use a special syntax highlighting theme: 9( $ curl cht.sh/lua/table+keys\?Q local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end6 to see all supported styles). Other cht.sh configuration parameters: 0Tab completionBash Tab completionTo activate tab completion support for 8, add the $ curl cht.sh/lua/table+keys\?Q local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end8 script to your $ curl cht.sh/lua/table+keys\?Q local keyset={} local n=0 for k,v in pairs(tab) do n=n+1 keyset[n]=k end9: 1ZSH Tab completionTo activate tab completion support for 8, add the 1 script to the fpath in your 2: 2Stealth modeBeing used fully unnoticed is one of the most important property of any cheat sheet. cheat.sh can be used completely unnoticed too. The cheat.sh client, 8, has a special mode, called stealth mode. Using that, you don't even need to touch your keyboard to open a cheat sheet.In this mode, as soon as you select some text with the mouse (and thus adding it into the selection buffer of X Window System or into the clipboard) it's used as a query string for cheat.sh, and the correspondent cheat sheet is automatically shown. Let's imagine, that you are having an online interview, where your interviewer asks you some questions using a shared document (say Google Docs) and you are supposed to write your coding answers there (it's possible too that you'll type in the questions on your own, just to show to the interviewer that you've heard it right). When using the stealth mode of 8, the only thing you need to do in order to see a cheat sheet for some question, is to select the question using the mouse. If you don't want any text in the answers and the only thing you need is code, use the 5 option when starting the stealth mode. 3Of course, this is just for fun, and you should never cheat in your coding interviews, because you know what happens when you do. Windows command line clientYou can access cheat.sh from Windows command line too. Use cheat.sh command line client for that: 6. It supports:
You can also use 7 command-line installer for Windows to get it: 4Self-HostingDockerCurrently, the easiest way to get a self-hosted instance running is by using the 8 file. 5This builds and runs the image with baked in cheatsheets and starts the app and a Redis instance to back it, making the service available at http://localhost:8002 This is currently an early implementation and should probably not be used for anything outside of internal/dev/personal use right now. Editors integrationYou can use cheat.sh directly from the editor (Emacs, Sublime, Vim, and Visual Studio Code are currently supported; not all features are supported by all plugins though; see below). Instead of opening your browser, googling, browsing Stack Overflow and eventually copying the code snippets you need into the clipboard and later pasting them into the editor, you can achieve the same instantly and without leaving the editor at all! Here is what it looks like in Vim:
If you use some static analysis plugin such as syntastic (for Vim), you can use its warning and error messages as cheat.sh queries: place the cursor on the problem line and press PATH_DIR="$HOME/bin" # or another directory on your $PATH mkdir -p "$PATH_DIR" curl https://cht.sh/:cht.sh > "$PATH_DIR/cht.sh" chmod +x "$PATH_DIR/cht.sh"4: explanation for the warning will be opened in a new buffer. Features supported by cheat.sh plugins for different editors: FeatureEmacsSublimeVimVSCodeIDEAQtCreatorCommand queries✓✓✓✓✓✓Queries from buffer✓✓✓Toggle comments✓✓✓✓Prev/next answer✓✓✓✓Multiple answers✓✓Warnings as queries✓Queries history✓✓Session id✓Configurable server✓✓✓✓Vim
Here is Vim configuration example: 6In this example, several Vim plugins are used:
Syntastic shows warnings and errors (found by code analysis tools: PATH_DIR="$HOME/bin" # or another directory on your $PATH mkdir -p "$PATH_DIR" curl https://cht.sh/:cht.sh > "$PATH_DIR/cht.sh" chmod +x "$PATH_DIR/cht.sh"5, PATH_DIR="$HOME/bin" # or another directory on your $PATH mkdir -p "$PATH_DIR" curl https://cht.sh/:cht.sh > "$PATH_DIR/cht.sh" chmod +x "$PATH_DIR/cht.sh"6, PATH_DIR="$HOME/bin" # or another directory on your $PATH mkdir -p "$PATH_DIR" curl https://cht.sh/:cht.sh > "$PATH_DIR/cht.sh" chmod +x "$PATH_DIR/cht.sh"7, PATH_DIR="$HOME/bin" # or another directory on your $PATH mkdir -p "$PATH_DIR" curl https://cht.sh/:cht.sh > "$PATH_DIR/cht.sh" chmod +x "$PATH_DIR/cht.sh"8 etc.), and PATH_DIR="$HOME/bin" # or another directory on your $PATH mkdir -p "$PATH_DIR" curl https://cht.sh/:cht.sh > "$PATH_DIR/cht.sh" chmod +x "$PATH_DIR/cht.sh"9 shows you explanations for the errors and warnings and answers on programming languages queries written in the editor. Watch a demo, where the most important features of the cheat.sh Vim plugin are shown (5 Min): Or, if you want to scroll and/or pause, the same on YouTube: Emacs
Visual Studio Code
Usage:
(GIF courtesy: Matthias Endler, @mre) Sublime
Usage:
(GIF courtesy: Gaurav Kukreja, @gauravk-in) IntelliJ IDEA
Usage:
(GIF courtesy: Szymon Przebierowski, @szymonprz) QtCreator
Current features:
(GIF courtesy: Pozemka, @pozemka) Special pagesThere are several special pages that are not cheat sheets. Their names start with colon and have special meaning. Getting started: 7Command line client 8 and shells support: 8Editors support: 9Other pages: 0SearchTo search for a keyword, use the query: 1In this case search is not recursive — it is conducted only in a page of the specified level. For example: 2For a recursive search in all cheat sheets, use double slash: 3You can use special search options after the closing slash: 4List of search options: 5Programming languages cheat sheetsCheat sheets related to programming languages are organized in namespaces (subdirectories), that are named according to the programming language. For each supported programming language there are several special cheat sheets: its own sheet, 03, 6 and 7. Say for lua it will look like: 6Some languages has the one-liners-cheat sheet, 06: 7
At the moment, cheat.sh covers the 58 following programming languages (alphabetically sorted): PrefixLanguageBasicsOne-linersWeirdnessStackOverflow 12Arduino✓ 13Assembly✓ 14AWK✓✓ 15Bash✓✓ 16BASIC✓ 17Brainfuck✓✓ 18C✓✓ 19Chapel✓✓ 20Clean✓ 21Clojure✓✓ 22CoffeeScript✓✓ 23C++✓✓ 24C#✓✓ 25D✓✓ 26Dart✓✓ 27Dephi✓ 28Dylan✓✓ 29Eiffel✓ 30Elixir✓✓ 31ELisp✓✓ 32Elm✓✓ 33Erlang✓✓ 34Factor✓✓ 35Fortran✓✓ 36Forth✓✓ 37F#✓✓ 38Go✓✓ 39Groovy✓✓ 40Haskell✓✓ 41Java✓✓ 42JavaScript✓✓✓✓ 43Julia✓✓ 44Kotlin✓✓ 45LaTeX✓✓ 46Lisp✓✓ 47Lua✓✓ 48MATLAB✓✓ 49Nim✓✓ 50OCaml✓✓ 51Octave✓✓ 52Perl✓✓✓ 53Perl 6✓✓✓ 54PHP✓✓ 55Pike✓ 56Python✓✓✓ 57Python 3✓✓ 58R✓✓ 59Racket✓✓ 60Ruby✓✓ 61Rust✓✓ 62Scala✓✓ 63Scheme✓✓ 64Solidity✓✓ 65Swift✓✓ 66Tcsh✓✓ 67Tcl✓✓ 68Objective-C✓✓ 69VisualBasic✓✓ 70VB.Net✓✓And several other topics, that are though related to programming, are not programming languages: PrefixTopicBasicsStackOverflow 71CMake✓✓ 72Django✓ 73Flask✓ 74Git✓✓Cheat sheets sourcesInstead of creating yet another mediocre cheat sheet repository, we are concentrating our efforts on creation of a unified mechanism to access selected existing well developed and good maintained cheat sheet repositories covering topics of our interest: programming and operating systems usage. cheat.sh uses selected community driven cheat sheet repositories and information sources, maintained by thousands of users, developers and authors all over the world (in the Users column number of contributors/number of stars is shown): Cheat sheetsRepositoryC/U*StarsCreation DateUNIX/Linux, programmingcheat.sheetsMay 1, 2017UNIX/Linux commandstldr-pages/tldrDec 8, 2013UNIX/Linux commandschrisallenlane/cheatJul 28, 2013Programming languagesadambard/learnxinyminutes-docsJun 23, 2013Goa8m/go-lang-cheat-sheetFeb 9, 2014Perlpkrumnis/perl1line.txtNov 4, 2011Programming languagesStackOverflow14MN/ASep 15, 2008(*) C/U — contributors for GitHub repositories, Users for Stackoverflow Pie diagram reflecting cheat sheets sources distribution (by number of cheat sheets on cheat.sh originating from a repository): How to contributeHow to edit a cheat sheetIf you want to edit a cheat.sh cheat sheet, you should edit it in the upstream repository. You will find the name of the source repository in a browser when you open a cheat sheet. There are two github buttons at the bottom of the page: the second one is the button of the repository, which belongs the current cheat sheet. You can edit the cheat sheet directly in your browser (you need a github account for it). There is an edit button in the top right corner. If you click on it, an editor will be open. There you will change the cheat sheet (under the hood: the upstream repository is forked, your changes are committed in the forked repository, a pull request to the upstream repository owner is sent). How to add a cheat sheetIf you want to add a cheat sheet, you have one of the following ways:
If you want to change an existing cheat sheet, you have to find the original repository (when you open a cheat sheet in a browser, you see the repository's github button in the bottom of the cheat sheet), the cheat sheet is coming from, and change it there. After some time the changes will be synchronized on cheat.sh. |