I’ve got this cheat sheet hanging on my wall. It’s for migrations. The Rails kind. It’s nice. I can never remember whether the method is add_column or create_column or what (it’s add_column btw). So, yeah. Todd’s got a bunch of TextMate ones hanging on his wall. Literally, like, four. And PJ? Don’t get me started.
The thing is, I’m a command line junkie. I use vim and svn like many other Rubyists. I wish there was a way to pull up cheat sheets from my command line, but unfortunately most cheat sheets are distributed as images (or PDFs) and just so damn pretty.
Until now.
Imagine a world, if you will, of plain text cheat sheets accessible from any Ruby capable command line. That world is the Internet.
sudo gem install cheat
Try it out:
$ cheat strftime
strftime:
%a – The abbreviated weekday name (``Sun’‘)
%A – The full weekday name (``Sunday’‘)
%b – The abbreviated month name (``Jan’‘)
%B – The full month name (``January’‘)
%c – The preferred local date and time representation
%d – Day of the month (01..31)
%H – Hour of the day, 24-hour clock (00..23)
%I – Hour of the day, 12-hour clock (01..12)
%j – Day of the year (001..366)
%m – Month of the year (01..12)
%M – Minute of the hour (00..59)
%p – Meridian indicator (``AM’’ or ``PM’‘)
%S – Second of the minute (00..60)
%U – Week number of the current year,
starting with the first Sunday as the first
day of the first week (00..53)
%W – Week number of the current year,
starting with the first Monday as the first
day of the first week (00..53)
%w – Day of the week (Sunday is 0, 0..6)
%x – Preferred representation for the date alone, no time
%X – Preferred representation for the time alone, no date
%y – Year without a century (00..99)
%Y – Year with century
%Z – Time zone name
% – Literal ``’’ character
Oh man that feels good. TextMate, anyone?
$ cheat strftime | mate
See all the available cheat sheets:
$ cheat sheets
Hot damn. Where’s all this coming from, though? I’ll tell you.
I’ve setup a little Camping wiki with a YAML backend from which the cheat command line tool gets its power. It caches stuff locally, of course. If you update a cheat sheet on the wiki and you’re not seeing changes on the command line, pass cheat the --new option:
$ cheat strftime --new
Here’s a few of the first cheat sheets added:
$ cheat assertions
$ cheat bash
$ cheat cheat
$ cheat migrations
$ cheat sprintf
$ cheat strftime
Please be kind to the wiki. And, uh, keep the cheat sheets Ruby-centric. Bash is okay but Python is banned.
Thanks to Hank and Evan for help finding bugs and that kind of thing. Enjoy.
Update:
Or, you know, $ inflate cheat. It’s like a free trial version.
The Windoze problems may or may not be fixed. Either way, there’s Cheat 1.0.1 on the gem server:
$ sudo gem update cheat
We’ve also got some new cheat sheets for you to consume:
$ cheat iomodes
$ cheat sti (single table inheritance)
$ cheat validations
Eric Anderson hacked a JEdit macro for Cheat. In Java, no less! Check it out in the comments. Where’s the TextMate Cheat macro, guys?
And hey, Digg.
Update 2: Ed Silva knocks it out of the park with his Cheat TextMate command.
Steps:- ctrl+alt+apple+b to open Bundle Editor
- Plus sign in the bottom left => New Command
- Name it Cheat.
- Put Ed’s code in the body
- Change the Output dropdown to Show as HTML
- Click on the Activation text field and hit ctrl+c (c for cheat!).
That’s it. Highlight a word in TextMate and hit ctrl+c. Lovely.
Evan Weaver, slayer of Indian Chiefs, wrote some smart plaintext wrapping now in use by Cheat. No more wrapping by hand!
New gem with wrapping, 1.0.2:
sudo gem update cheat
Finally, new sheets are slowly popping up. Get ‘em before your teacher catches you:
$ cheat deprecated (inspired by topfunky and Kevin Clark)
$ cheat svn
$ cheat wmii3 (you know about wmii3, surely)
$ cheat environments (more lewt stolen from Kevin Clark)
Oh yeah, we’ve got an RSS feed for recently updated cheat sheets making the rounds, too. That’ll help you figure out if you need --new.
Don’t hate on Python. It will come silently in the night and indent you, and then you’ll be sorry.
This is SO COOL! Thank you tons!
Hey, this is pretty cool! When can we expect the source code for the interface and for the backend?
Oops, just found it. Nevermind that :)
I had to change HOMEPATH in def sheets; end to HOME to make it work on win32. HOMEPATH doesn’t have the HOMEDRIVE which seems to make mkdir choke.
Some line wrapping would be nice, dooing it by hand is ugly and hard.
The ENV[‘HOMEPATH’] doesn’t seem to be the best ENV option (that is, it isn’t working :)
HOMEPATH=\Documents and Settings\Nic Williams (note: no drive path)
Alternatives: USERPROFILE=C:\Documents and Settings\Nic Williams
Or combine: HOMEDRIVE=C: HOMEPATH=\Documents and Settings\Nic Williams
Anyone have thoughts on which is best (and/or why HOMEPATH might be incorrect on my win32 laptop?)
Nic
Yeah, what yerejm said… :)
I added a validations and a single_table_inheritcance one for all to enjoy.
I like to work at both the command line and in my text editor (JEdit). If you are using JEdit and want to access these cheat sheets right from your text editor I put together the following BeanShell script. It will execute the cheat command with the name you give it and put the output in a simple dialog box.
My Java is quite rusty so this may not be the best implementation:
Simply map this to a key command (I have it mapped to Ctrl-Shft-C) and you can quickly bring up your cheat sheet in Jedit.
Cool. What a nice idea!!!
These are flippin’ sweet. Absolutely a great idea. I can never remember strftime.
Chris- I wrote up a blog post asking people to test the windows new windows cache code at (http://concentrationstudios.com/articles/2006/09/02/cheat-tests) I am going to try writing up some tests soon. At least I have some test stubs :)
Dugg! http://digg.com/programming/Ruby_Help_on_the_Command_Line
v1.0.1 works great on Win32 now. Thx guys!
Here’s a TextMate command I set up:
word=${TM_SELECTED_TEXT:-$TM_CURRENT_WORD} echo “
Ok, that got mangled. See my blog entry:
http://weblogs.litmusgreen.com/ed/archives/002498.html
Can you include the whole cheatsheet in the RSS feed?
Harriet: The password is jalapeno.
Dr Nic: Done!
Very cool, I just scraped the relations docs for rails and dropped those in since I’m always lookin’ em up. Now to hook it up with TextMate (the one true $EDITOR)
Great stuff!
Idea: would be nice to have an URL property for each cheat. Like where can we get the code. >cheat microformats_helper—url
Any reason it’s not up on rubyforge? appending that—source to the gem command line is way too much work :-p
That’s cool!
Blaine, it’s on rubyforge. Just $gem install cheat :-)
cheat sheet—add cheat sheet—edit
Someone please fix my horrible horrible hack :)
Thanks for making this! I have one question though, how do you get mac keyboard symbols to show up in the terminal? For example, some of the symbols in the textmate_rails cheat sheet? Thanks!
Kick ass!
Ok, now implement all of my MAN pages :)
if you want to call cheat from within cygwin bash but you are using the windows version of ruby (don’t ask ;) then the following additions to your .bashrc will make it work without having to re-write the ruby:
: ${HOMEDRIVE:=c:}; export HOMEDRIVE : ${HOMEPATH:=$(echo ~)}; export HOMEPATH alias cheat=’cheat.cmd’
I’m having issues getting cheat to work with Instant Rails. I was able to install it using the ‘gem install cheat’ command but when I run it mkdir seems to choke with a ‘No such file or directory error’ Any help will be appreciated. Thanks.
How to store in local?
This is great! I’ve installed it successfully and ‘cheat migrations’ works a treat but ‘cheat cheat’ doesn’t:
$ cheat Looking for help? Try http://cheat.errtheblog.com or `$ cheat cheat’
$ cheat cheat Error!: Cheat sheet `cheat’ not found.
Any ideas?
man strftime ?? It is just calling the C function
I love cheat :
) and I love vim :) so there you go: a cheat wrapper for vimCheers!
I added a cheat function to my ”.bashrc” file, so I got paging without typing “more”
function cheat() { /usr/bin/cheat ”$@” | more; }
Chime in.