Wednesday, May 21, 2008

Invoking TextMate from a remote machine

I edit all my script files via TextMate, but they live on remote drives (mounted via sshfs). I'm always logged in to the remote machines to run scripts etc. Usually I'll open remote files via Quicksilver, but when I create a new file this isn't an option yet and so it's tedious. Anyway, I've cooked up a quick script (with some help) to open TextMate from a remote machine.

Try it, YMMV:
#!/bin/bash

cd $(dirname $1)

PWD=`/bin/pwd`

BASENAME=$(basename $1)

ssh pasadena "osascript -e \
'tell app \"Terminal\" to do \
shell script \"/usr/local/bin/mate /Volumes/emil$PWD/$BASENAME\"'" >& /dev/null &
pasadena = name of my Mac OS X machine
/Volumes/emil = sshfs mount point

Update: I removed the "-w" option (I didn't want TextMate to wait for the file to be closed) and redirected all the garbage to /dev/null.

Update 2: Support arbitrary (i.e. also absolute) paths.

Update 3: this is broken on Snow Leopard :(

Update 4: Here's a workaround, although it's a bit ugly as you need to invoke sudo.