Cheatsheet syntax ----------------- * [Syntax overview](#syntax-overview) * [Folder structure](#folder-structure) * [Variables](#variables) * [Advanced variable options](#advanced-variable-options) * [Variable dependency](#variable-dependency) * [Multiline snippets](#multiline-snippets) * [Variable as multiple arguments](#variable-as-multiple-arguments) ### Syntax overview Cheatsheets are described in `.cheat` files that look like this: ```sh % git, code # Change branch git checkout $ branch: git branch | awk '{print $NF}' ``` Lines starting with: - `%`: determine the start of a new cheatsheet and should contain tags - `#`: should be descriptions of commands - `;`: are ignored. You can use them for metacomments - `$`: should contain commands that generate a list of possible values for a given argument [:information_source:](#variables) - `@`: should contain tags whose associated cheatsheet you want to base on [:information_source:](#extending-cheatsheets) All the other non-empty lines are considered as executable commands. ### Folder structure It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. ### Variables The interface prompts for variable names inside brackets (eg ``). Variable names should only include alphanumeric characters and `_`. If there's a corresponding line starting with `$` for a variable, suggestions will be displayed. Otherwise, the user will be able to type any value for it. If you hit `` the query typed will be prefered. If you hit `` the selection will be prefered. ### Advanced variable options For lines starting with `$` you can use `---` to customize the behavior of `fzf` or how the value is going to be used: ```sh # This will pick the 3rd column and use the first line as header docker rmi # Even though "false/true" is displayed, this will print "0/1" echo $ image_id: docker images --- --column 3 --header-lines 1 --delimiter '\s\s+' $ mapped: echo 'false true' | tr ' ' '\n' --- --map "grep -q t && echo 1 || echo 0" ``` The supported parameters are: - `--column `: extracts a single column from the selected result; - `--map ` *(experimental)*: applies a map function to the selected variable value; - `--prevent-extra` *(experimental)*: limits the user to select one of the suggestions; - `--fzf-overrides ` *(experimental)*: applies arbitrary `fzf` overrides; In addition, it's possible to forward the following parameters to `fzf`: - `--multi`; - `--header-lines `; - `--delimiter `; - `--query `; - `--filter `; - `--header `; - `--preview `; - `--preview-window `. ### Variable dependency The command for generating possible inputs can implicitly refer other variables by using the `` syntax: ```sh # Should print /my/pictures/wallpapers echo "" $ pictures_folder: echo "/my/pictures" $ wallpaper_folder: echo "/wallpapers" ``` If you want to make dependencies explicit, you can use the `$varname` syntax: ```sh # If you select "hello" for , the possible values of will be "hello foo" and "hello bar" echo # If you want to ignore the contents of and only print : ; echo $ x: echo "hello hi" | tr ' ' '\n' $ y: echo "$x foo;$x bar" | tr ';' '\n' ``` ### Extending cheatsheets With the `@ same tags from other cheatsheet` syntax you can reuse the same variable in multiple cheatsheets. ```sh % dirs, common $ pictures_folder: echo "/my/pictures" % wallpapers @ dirs, common # Should print /my/pictures/wallpapers echo "/wallpapers" % screenshots @ dirs, common # Should print /my/pictures/screenshots echo "/screenshots" ``` ### Multiline snippets Commands may be multiline: ```sh # This will output "foo\nyes" echo foo true \ && echo yes \ || echo no ``` ### Variable as multiple arguments ```sh # This will result into: cat "file1.json" "file2.json" cat $ jsons: find . -iname '*.json' -type f -print --- --multi --map "navi fn map::expand" ```