I came across a great utility for Rails development this week. The guys over at Err the Blog created a gem called cheat that basically wires up wiki-driven Ruby cheat sheets with Terminal. After installing the gem:

$ sudo gem install cheat

...you've automatically got access to any of the cheat sheets stored at cheat.errtheblog.com-- which is actually a wiki that you can, well, do wiki-ish stuff with.

Sample output:

$ cheat to_i

to_i:
  "1".to_i         # => 1
  Integer("1")     # => 1
  
  "2two".to_i      # => 2
  Integer("2two")  # => ArgumentError: invalid value for Integer: "2two"
  
  "three".to_i     # => 0
  Integer("three") # => ArgumentError: invalid value for Integer: "three"
  
  "100".to_i(16) # => 256
  "foo".to_i(36) # => 20328
  
  Time.now.to_i # => 1227934942
  open('foo.txt').to_i # => 3
  
  nil.to_i # => 0

Pretty cool.

Shortly after Cheat came out, Ed Silva released a little script for integrating Cheat into TextMate. Since I've switched back to BBEdit for my Rails development, I decided to do something similar for BBEdit.

All you need to do is download (and unzip) the script linked below. Copy it into ~/Library/Application Support/BBEdit/Scripts/ and it will show up in your Scripts menu in BBEdit.

For added convenience, add a keyboard shortcut. Pull up Window > Palettes > Scripts, select 'Rails Cheatsheet', and click Set Key. I use command-R.

To use the script, highlight a term in a BBEdit window (like strftime) and either hit your keyboard shortcut or select the script from the Scripts menu item. A new window will open, populated with the cheatsheet. If you invoke the script without first highlighting anything, you will be presented with a dialog box from which you can enter the name of a specific cheat sheet, get help with Cheat, or access a list of available cheat sheets.

(Thanks to John Gruber for providing indirect help with the AppleScript through the excellent code examples on his site.)

Download the Rails Cheatsheet Script for BBEdit (7k)

Related Articles


Comments

Lorin Rivers
December 22, 2008 at 8:46 AM

This is quite cool! I didn't like how your version made the cheat sheet "dirty" (and not in a good way). I amended it to use the command-line bbedit instead. replace the last bit with: do shell script "echo " & (quoted form of cheatsheet) & " | /usr/bin/bbedit --clean --new-window" I'll email a copy in case your commenting blows up the code above.

Corey Ehmke
December 22, 2008 at 9:19 AM

Thanks, Lorin. I've uploaded the revised version of the script.
Leave a Comment


IdolHands.com Spam-o-MeterTM
Bot
Spammer
Moron
Human






* Required fields.