It’s been a while since I mentioned my macOS key bindings, so if you’re new around here, let me point you to my previous work.
I’m pretty crazy about text input shortcuts and have spent a fair amount of time honing a system that lets me use selection, editing, Markdown, HTML, and other shortcuts everywhere you can type on macOS. I’m so used to them I make a mess typing on other people’s computers. I try to avoid doing that. Typing on other people’s computers, I mean.
I share a large collection of all of my favorite key bindings on GitHub. Everything is contained in the file DefaultKeyBinding.dict
, which is what macOS reads all key bindings from. In that file I use formatted comments to describe each binding, and I can generate the README and blog page by parsing the bindings file itself. The script that generates the table of shortcuts creates it in Markdown and then uses MultiMarkdown to output the document, ready for GitHub or my project page.
I also generate a cheat sheet for Cheaters from it, but I’ve been using Dash more than Cheaters for the last couple of years. So I wanted my key bindings in a Dash docset for quick reference.
Yes, there is such a thing as too many shortcuts. I walk that line. But I manage to not have so many that I’m accidentally triggering them while doing something else, so I think it’s just the right amount. It’s just more than (even) I can remember all at once. Which is why a searchable cheat sheet you can pop up with a keystroke is handy.
So I modified the documentation generator to output a template for the cheatset gem. It will read whatever is in your KeyBindings.dict file and generate a Keybindings.docset
file for you based on the definitions and comments in the file. So you can take my oversized DefaultKeyBinding.dict
file, trim it down to what you want to use (leaving comments in place), and generate a custom cheat sheet for your own key bindings.
Download the code to get the script (and the bindings file). Make it executable with chmod a+x cheatset_keybindings.rb
. Before running it, you’ll need to install the cheatset gem: gem install cheatset
should do it, though you might need sudo gem install cheatset
, depending on your setup.
You can point the script to whatever DefaultKeyBinding.dict
you like by passing a path as an argument. It will default to using the one in ~/Library/KeyBindings
.
The script can output the key combinations either as symbols, e.g. ⌃⌘p
or as names, e.g. CTRL+CMD+P
. “Name” is the default format; to output symbols instead, use --format symbol
.
You can also change things like the docset title and description using command line flags. Just run cheatset_keybindings.rb -h
to see the options.
By default the script will generate the template, then run cheatset to generate the docset, and then delete the template, leaving just the docset. If you just want the template, run the script with --save
. Then you can edit the template and run cheatset generate TEMPLATE
yourself.
I made this because I needed it, not because I expected it to be a popular project. If it’s of use to you, though, please enjoy!