Start writing your very own cheat sheets in your way and make them searchable using Alfred!
Every sheet shown in the demo should be your knowledge base and is totally customizable.
This project was initally inspired by cheat. I attempted to wrap around it but failed because that project wasn't intended to be wrapped around. So this project ended up a separate one. These two projects serve similar purpose in different working environments. With the help of alfred, your efficiency in searching your cheat sheets will be significantly boosted. And the better news is, you're in complete control of your cheat sheets unlike tldr (It's good though if you want it "just work").
I built this workflow because:
I want faster searching than the original cheat because that project is commandline based. Sometimes I want a very quick view and don't wanna popup a shell.
I want to build my own knowledge base instead of community-driven cheat sheets like tldr does.
All codes in directory
workflow are dependencies from this project. They're not my work and is the only "dependency" for this project. Since it's included in this repo, the workflow user doesn't have to concern about dependencies.
You define a directory to store your cheat sheets, which are essentially text files. And name the file the command your wanna record. e.g,
tar etc. (tips: you can start with the cheat sheets provided by cheat)
You write your cheat sheet according to the rules (very intuitive and tolerant) bit by bit.
Tell the workflow where that directory is and start searching.
First, you need to specify your sheet directory like this. Otherwise, it doesn't work. Both absolute or relative path will work.
Then, you're good to go.
To list all your cheat:
To search and list the content of one of your cheat:
cheat <sheet name>. Fuzzy search and autocomplete is supported.
To search in a specific sheet indexed by some keyword:
cheat <sheet name> <keyword>.
To search across all your sheets for some keyword:
cheat --search <keyword>
When you find your desired record and you wanna paste it directly to the app you're using (e.g., Terminal or iTerm2), hit
Enter. This behavior can be changed in the Alfred setting (#3).
If you like to just copy, hit
It's not even a rule... You just need to remember two things when writing your cheat sheet:
Comment first, then the command.
comment, command pair with 2 newlines. (one newline visually)
e.g. this cheat sheet is called
demosheet. Its content is the following:
# This is a one line comment. command one goes here. # This is a second comment for the second command # Yes we can have multiple line comment. # But remember only the last line will be considered "command". command two goes here # command three: in rare cases you don't have any comment, keep an empty # above. # Any failed parsing will be ignored, like this line because it isn't associated with a command or this line because it's a single line.
The above sheet will be parsed like this:
Kindly note that hidden cheatsheets (starting with
.) will be ignored and hidden directory will be ignored as well. Hierachical structure is supported but that's only for your management purpose. This tool will only "flatten" every cheatsheets in the base directory. i.e.,
cheat/mydir/yourdir/somecheat will be equivalent to
cheat/somecheat in its perspective. Also make sure you don't have duplicated cheatsheets in different directories otherwise only one of them will be dominant. Thanks for @Blackvz for the feature suggestion #4.
This workflow works out of the box (zero dependencies). It's tested on macOS 10.14.5 Mojave with Alfred 4. You need the powerpack to get it working. I believe it works with Alfred3 on any macOS after 10.10 Yosemite but that hasn't been tested. Report an issue if there's a problem.
Any idea of improvement will be welcomed. But I don't wanna add the feature of modifying cheat sheet right in Alfred because it isn't what it is supposed to do. Use vim or other editors you like.