TextMate "Paste Line/Selection Online" command mod

Written . Tagged OS X, Ruby, TextMate.

The “Paste Line/Selection Online” (a.k.a. ”Pastie”) command in TextMate is great. You can send code straight from the buffer to a paste service with a keyboard shortcut (⌃⌥⇧V).

The command opens a very full-featured dialog:

[The standard dialog]

You can have the pastie URL sent to Colloquy (IRC) or Adium (IM). I never use this. I just want it to go into my clipboard. From there, I can paste it into an IRC or IM message. Selecting the right conversation in the dialog is more work, and only the URL is sent: you have to set things up before or quickly explain yourself.

Furthermore, sometimes pasting will take several seconds. I’ve found myself pasting and undoing repeatedly until the URL appears. TextMate will flash a tooltip when pasting is done, but that doesn’t help you if you’re in another app by then.

Oh, and the only thing I really want to choose is the privacy level: if the paste should be public for everyone to see, or private. In the standard dialog, the privacy setting is a checkbox that requires using the mouse or tabbing extensively.


I made a new front-end for the command that does what I want and nothing more:

[Modified dialog]

You just press to paste it as private, hit the space bar to paste it as public, or to cancel. The URL is copied to clipboard.

The rationale for having “Private” be the default button is that it’s the less “dangerous” action – it’s no big deal to make code private that was really meant to be public, but it would suck to get it wrong the other way around. Also, most of the time, I don’t care to have pastes available to people I didn’t give the URL to.

Oh, and the command Growls when done:

[Growl dialog]

Get it here. Note that it replaces the default Pastie command (same guid).

You need Growl with growlnotify.

There is no option for soft-wrapping. I never used that checkbox. The default smarts is to soft-wrap text and not wrap code (based on the grammar scope). Works for me.

You can easily configure the script to not Growl or copy to clipboard, and to do open the URL in the default browser or whatever else you prefer that the old dialog did.

Update 2007-07-11
I realized I’d prefer it to pastie document or selection, not line or selection. If you agree, get this version of the command instead. So if no text is selected, it will pastie the entire document contents instead of the current line. I also updated both the old and the new versions of the command to ensure they finish copying to clipboard before growling; before this update, it would actually growl just before copying.
Update 2007-09-21
Both versions of the command have been updated to use the URL http://pastie.textmate.org/pastes instead of the deprecated http://pastie.textmate.org/pastes/create.
Update 2007-10-27
Both versions of the command have been updated since the way to get the user’s name has changed. By default, your name will go to Pastie as “Real Name (username)”. If you want to use something else, set the TM_AUTHOR environment variable. Another minor change is that the command now uses /usr/local/bin/growlnotify if it can’t be found elsewhere in your PATH. This means no painful search path configuration if you stick it where it wants to go.