Moving Off Tumblr!

Hey Friends!

Wanted to post a heads up here, I have migrated textmateuser off of tumblr over to a new WordPress I just finished. Needed a bit more power to do everything I wanted, so please come visit at textmateuser.com for all the wonderful tip here, and more!

Thank you for your support, see you soon!

Also, don’t miss!

In case you have not moved to the new site, there is a new contest running to win a free license for TextMate!

So get over there and enter! Thanks!

A (Better?) Web Page Source in TextMate Solution

The curl command example I submitted the other day is OK, but it’s got some drawbacks: If the URL is for a site that requires login, it’ll fail because curl just naïvely gets the URL without attempting to log in. Or maybe the page you want has some cookies on you that makes what you’re seeing in your browser different from what curl sees (unless you pass the cookie data to curl and blah blah blah).

So here’s something you can do if you want a command in TextMate that gets the source of the frontmost tab/window in Safari (yes, it only works with Safari because it relies on Safari’s AppleScript-ability):

osascript -e 'tell application "Safari" to (source of current tab of window 1)' | awk '{ sub(/\r$/,""); print }'

Breakin’ it down: osascript is a command that interprets AppleScript. The -e option tells it to execute the following line. That line, in turn, tells Safari to return the page source of the frontmost tab. The result is then piped (|) to the awk command, which replaces CRLF (Windows-style) line-endings with Unix line-endings, and prints the result to stdout.

You can either run that command in the terminal, or in a TextMate document using ^R, and get the source right there, or you can make a new command in whatever bundle you choose (maybe a new one for your own custom commands?), and paste the line in there. Since it’s bash, the new command can be just that line and nothing else. Set the command’s input to Nothing and its output to Create New Document. And… disco.

It may not be a command that you’ll use very much, but it’s a neat example because it utilizes a bunch of TextMate and Mac OS X features in one go.

But: It ain’t perfect. Besides being Safari-only, the source you get won’t contain markup that was added/changed via JavaScript, so very Ajax’y/Web 2.0-ish pages will have trouble. Second, if the AppleScript line fails (which it can) you’ll get a new document just containing an ugly error message. So there are a bunch of improvements that can be made to the user-experience (e.g. show a tool tip if there’s an error instead of creating a useless document). But that’s some homework for you.

Change Paste Online Option To Public

I kept forgetting to set my pastie to public when uploading, so I found how to make it public by default!

Nice collection of shortcuts

This dude put together around 20 TextMate shortcuts in a list, check it out.

cmd-ctrl-t

CrimsonScythe mentioned it on irc, and it’s in the ##textmate channel’s topic, but I’ll second (third?) it here - it’s just damn useful: ctrl-cmd-t

That, and the “Show Keyboard Shortcuts” command in the TextMate bundle.

A neat theme

The RailsCasts theme is great - I’ve been using it for years now: http://railscasts.com/about

That theme is probably also a good “template” to use for custom themes. It’s got pretty much all of the scopes that I run into in markup/JS/Ruby/PHP/CSS/shell scripting/whatever, but it’s still a managable number of scopes to fiddle with

Skip the terminal (sometimes)

It’s right there in the Text-menu, but I often forget it myself: Execute Line Inserting result (ctrl-R)

Now, you can’t use this for the defaults write…-thing because you need to close TextMate before running that, but a lot of other stuff it’s pretty useful.

Say you want the source of a web page in TextMate, you can do just write

curl -s http://textmateuser.com/

on a line in TM, and hit ^R. Bingo. If your terminal-fu is strong, you can get far.

Change Default Drawer Side

In case someone has not moved into the realm of Project+ yet, the standard TextMate project drawer still works fine. However, before switching, I was constantly annoyed that the drawer for new projects always opened on the right of the main document. The only way to move it left was to close the drawer, move the window all the way to the right of the screen, then reopen the drawer. This would force it to open on the left because it deemed there was no room on the right.

Forget that!

Here is a much better and faster way to handle the issue if you so desire.

Enter The Terminal

If you have never seen it, it looks like this,

Before you start this process, be sure to close TextMate. Once closed, and you are safely inside the terminal, type the following;

defaults write com.macromates.textmate OakProjectDrawerPrefersRightEdge -bool NO

What the hell is that?

Glad you asked. The command defaults.write is an OS X term saying “hey, we are about to edit an application’s preference file!” The com.macromates.textmate is the domain for the TextMate preference listing, and OakProjectDrawerPrefersRightEdge is, well you can guess what it is. The Oak in the front is simply a namespace. -bool is a flag saying we are changing the boolean value to no.

Now open a TextMate project and revel in the awesome.

Working with text, including line duplication, auto-indention and quickly creating html tags.

Creating Time Saving Snippets

This is kind of take-two of a video I made a long, long time ago. I have since learned much better ways to make awesome snippets, so here is the updated awesome. Enjoy!

The Code

-moz-transition: ${1:all} ${2:0.3}s ${3:ease-out};  
-o-transition: ${1:all} ${2:0.3}s ${3:ease-out};  
-webkit-transition: ${1:all} ${2:0.3}s ${3:ease-out};  
transition: ${1:all} ${2:0.3}s ${3:ease-out};
$0