Ernie Miller

No, I don't work in NYC, DC, or the valley, and I'm cool with that.

RSS Feed

TextMate 2 + rmate = Awesome

Posted by Ernie on December 12, 2011 at 6:44 pm

I heard TextMate 2 will be released tomorrow and decided to try it out. One really cool thing that was added to TM2 is the rmate script. This is a nifty little script that will let you edit files on a remote server through your running instance of TextMate 2. Here’s how to get it working using SSH tunneling.

Verify it’s enabled

TextMate 2 Terminal Preferences

TM2 Terminal Preferences

On the current TM2 alpha, the default is to enable rmate for local clients, as shown here. That’s just fine, because we want to encrypt our file editing activity via SSH tunnel, anyway. As far as TextMate’s concerned, our rmate is local.

Just verify that the “Accept rmate connections” checkbox is checked, “Access for” is set to “local clients” and note the port number (52698 be default) or set it to one of your choosing.

Once you’ve done so, click on the “rmate” link in the preference’s descriptive text to open the rmate script in a TextMate window. Copy the script’s contents.

The Tunnel o’ (TextMate 2) Love

If you’re not familiar with SSH tunneling, all you need to know for the purposes of setting this up is that SSH allows you to send your traffic destined for certain ports over the SSH connection to your local machine (possibly to an alternate port). SSH to a server you’d like to edit some files on, using the following command:

ssh -R 52698:localhost:52698 <user>@<server>

Be sure to replace 52698 with the port you chose, if you altered it.

This command says that for the duration of your SSH session, any connections to port 52698 on the remote machine will have their traffic forwarded on to your local machine’s port 52698, where your running TextMate 2 instance will happily accept it.

Copy the rmate script (first time only)

We need to get the script installed on the server. Since you’re already SSHed onto the server, the easiest way to do that is probably just to paste the contents of the script into a new file. Substitute your own editor of (second) choice as appropriate:

# If installing for all users...
sudo vi /usr/local/bin/rmate
# If installing for yourself (make sure it's in your PATH!)... 
vi ~/bin/rmate
# Make it executable
chmod +x <previously-used-directory>/rmate

Now, if all went well, you should be able to run:

rmate rmate_rocks.txt

A TextMate window should pop up with a blank file. Type whatever you like into the file (might I suggest “rmate rocks!”) and save it. On the server, your rmate_rocks.txt file will have been saved!

Troubleshooting

/usr/bin/env: ruby: No such file or directory

Your server doesn’t have Ruby installed. The rmate script is written in Ruby, so you’ll need to install a Ruby interpreter.

Warning: remote port forwarding failed for listen port 52698

Someone else is already using port 52698 on the server for something. No big deal. Disconnect from the server, and choose another port:

ssh -R <my-port-number>:localhost:52698 <user>@<server>

Now, when you run rmate, you’ll just need to specify the alternate port, like so:

rmate -p <my-port-number> rmate_rocks.txt

Since the SSH tunneling takes care of forwarding the rmate traffic to 52698 locally, you don’t have to change any setting in the TextMate 2 Terminal preferences!

That’s it!

I’m really excited about TextMate 2, and haven’t gotten to play around with it much yet, but I hope this helps you get started with what I think is one of the coolest new features. Thanks for reading!

[Update 12/14/11: If you want to further simplify your rmate setup, check out Jon Simpson's writeup on setting up RemoteForward in your SSH configuration file]

Filed under Blog
You can leave a comment, or trackback from your own site.
  • Guest

    if you are into that sort of things, Transmit/Cyberduck approach requires much less configuration.

  • http://metautonomo.us Ernie Miller

    I wondered how long it’d take someone to bring that up. ;)

    Yeah, you can do that, but you’re stuck browsing the filesystem through that application, then.

    With rmate, it works just like running vim on the server — can use it with sudo, etc.

  • Guest

    I use Transmit daily, pops up with one command using Alfred, and right click on the file and it opens up in TextMate 1 and I’m editing on a remote file and I always use SSH keys in my Transmit connections compared to FTP. So doesn’t seem to be any faster using this other more complicated method. Though like Android users, some people prefer more complex methods of doing simple things because it’s more ‘fun’. All the power to you!

  • Tomasz Werbicki

    I’m pretty sure what was meant here is that you can mount SSH directory as a volume in your filesystem and then edit your files just like there were local.

  • http://metautonomo.us Ernie Miller

    Trasmit or Cyberduck allows this? I don’t recall that being a feature bundled with Cyberduck, at least.

  • Guest

    Even more hoops to jump through when you use screen/tmux on the remote server, cause they don’t retain your $SSH_CONNECTION for obvious reasons. As for sudo quick edits I’d use vim remotely.

  • Anonymous

    I dearly love Transmit, but often I’m working in an ssh session on the server. No matter how fast I can pop Transmit open I still have to navigate through the filesystem to find the file I want to edit, right click to open, save and close. There is *no way* using Transmit is going to be faster.

    rmate is going to be a killer feature for me to quickly edit a configuration file etc. without having to stumble through VIM which I am still embarrassingly weak at using.

    PS. I’m not an Android user but that cheap shot isn’t even warranted. What’s more complex, set up rmate once, then whenever you’re in a ssh shell, with *one command* open and edit a file on a remote server – or – switch from a terminal session to a ftp application, navigate the filesystem on the application, right-click open file using “Textmate”?

  • Pingback: TextMate Blog » Alpha Tidbits

  • Anonymous

    Transmit does allow that yes, but that still doesn’t help if you’re working on a remote server. Generally if you’re SSH’d into a remote server, you want to be able to run other commands on it. You can’t do that if you’re just accessing a mounted filesystem.

  • Michael Bond

    The problem with this, over using transmit, is that you need to install rscript on all your servers. If you have, for example, 15 or 20 servers (i actually have 21). Then if the script changes you need to update it on all your servers. Its a nice touch, i always have a command line open to the server’s i’m looking at anyway … but I frequently have to have a transmit window open anyway for copying other things around. 

    If i just need a quick edit, i’ll use emacs from the command line. its keybindings should be more familiar to you than vim. 

  • RDSchaefer

    Then why not just run vim on the server and edit the file ‘locally’?  This whole thing just seems way too complicated.  If I’ve already got a secure console window open, I’m just going to use the tools that are already there.

  • http://metautonomo.us Ernie Miller

    Any number of reasons, chief among them being that some people just prefer using TextMate for editing. Not everyone is comfortable in vim, though I agree that they should consider familiarizing themselves.

    If you normally read this blog, you’ll notice it’s generally directed at a more technical than most, to help a greater percentage of readers.

  • http://www.jonsimpson.co.uk Jon Simpson

    Thanks for the overview of rmate – One thing worth mentioning is that you can set up the forward automatically using RemoteForward in your ssh config file for any servers you use regularly & have installed it on, which makes it pretty painless to use. I usually use Transmit Disk – but this is much more convenient once configured if you tend to have a terminal in the right place remotely for your edit session.

    I wrote up a quick guide to setting up the RemoteForward on my site.

  • Anonymous

    Is there any chance that the rmate script could be modified to handle directories, as well as single files?

  • http://metautonomo.us Ernie Miller

    I’d love to see this, but I think it’d involve a lot more than just an rmate update — the TextMate application that rmate talks to would have to be capable of receiving filesystem information, and then there’s the stuff like SCM badging and such in the sidebar. I think it’s somewhat unlikely.

  • http://jaylevitt.myopenid.com/ Jay Levitt

    If you want to do this without TextMate 2, here’s a hacky thing I cribbed together a while back: https://github.com/jaylevitt/textmate_remote

  • http://twitter.com/pelted Chris Born

    The big thing here for me is being able to use ‘sudo rmate’ to open remote config files in my local TM. This is one thing Transmit can not do, and since I disable root ssh logins this is just a beautiful way of editing. I don’t mind VIM or Nano, but sometimes the limitations of the console are just time wasting. This is killer.

  • http://schinckel.net Matthew Schinckel

    You can also get rid of the warning about forwarding failure if you have shared connection on to that server. Plus, it is faster to open second/third/nth connections to that same server.

  • http://schinckel.net Matthew Schinckel

    Anyone able to figure out how to pipe text through rmate and get it to work?

  • Aziz

    I like your minimalist approach to things RDSchaefer. Ernie, I’m sorry, but TextMate just doesn’t cut it for me, it’s too colorful and distracting. I need something like Vim, something ugly, where I get in and out quick.

  • Lucas Dohmen

    This is amazing! Thank you for that :) Called the command “mate” on the remote server – now I can type “mate” wherever I am. This is so freaking cool!

  • Anonymous

    The server I SSH into doesn’t have ruby installed. Any other ways to get rmate working?

  • Ssss

    I’m getting:

    `initialize’: Connection refused – connect(2) (Errno::ECONNREFUSED)

    Any clues as to the nature of this error?  It’s coming from one of those Unix servers on which all the software seems to be from 1995 despite it being an HPC cluster.

  • Ssss

    Of course I forgot to add that server to my ~/.ssh/config file.  Problem solved.

  • Pingback: TextMate 2 | Cai Durbin

  • http://twitter.com/caidurbin Cai Durbin

    Great 

  • Pingback: TextMate 2 Articles | The Doctor What

  • Pingback: Rrrrrrrrmate | Geek update

  • Trey Shugart

    If you use Puppet – which is probably smart if you have 21 servers – why don’t you just update your configuration to include that script on all your servers?

  • http://twitter.com/nledez Nicolas Ledez

    Hello, if you want to have config files for rmate, you can try my pull request:
    https://github.com/avian/rmate/pull/2

About

I'm Ernie Miller. But then, you probably knew that by looking at the page title, or the URL. I'm a Ruby programmer in Louisville, Kentucky. This blog used to be called "metautonomo.us", which I thought was kind of clever, but nobody, including me, could type it. Lesson learned.