Custom TextMate commands for ruby and scp

If you’re a Mac user and you’re not using TextMate, then hurry up and join the bandwagon. This is a powerful text editor for Mac OSX, which I use for just about any type of project be it C#, Java, PHP, Perl or even COBOL. What makes this tool so powerful is your ability to customize it to your heart’s content.

Take for example the following scenario. I use this editor to code from my sandbox, and use custom bundles to maintain versioning with my CVS server. Most bundles are a command click away, say for example, I need to add a file to the repository, I just hit Ctrl-Shift-Z and I’m presented with a CVS specific dialog.


You can also add your own custom commands to the bundles, building on what others in the community have already published. I think this is what makes the tool so powerful! The fact that thousands out there in the development community are adding customizations to TextMate regularly makes this an extremely useful and up to date tool.

I found when editing project files I wanted to be able to scp the current file being worked on up to my development server. To do this, I just added a custom command that invokes some ruby to do the dirty work for me, without ever having to open up a console to do it.

"${TM_RUBY:-ruby}" -r "$TM_SUPPORT_PATH/lib/shelltokenize.rb" < scp_user = ENV['SCP_USER'] || "tim.koopmans"
scp_port = ENV['SCP_PORT'] || "1234"
scp_host = ENV['SCP_HOST'] || "10.1.2.3"
scp_path = ENV['SCP_PATH'] || "/path/to/remote/files"
TextMate.selected_paths_array.each do |path|
puts %x{scp -P #{scp_port} "#{File.dirname path}/#{File.basename path}" #{scp_user}@#{scp_host}:#{scp_path}/#{File.basename path} && echo Finished secure copy! || Problems encountered!}
end
END

The above code simply populates some variables (after first checking for TextMate environment variables, if not exist then populate with defaults in the script), then uses a ruby puts command to scp the file being worked on up to the development server. I'm using ssh key pairs here, so I don't require password authentication. Link that command to a key equivalent e.g. Ctl-Shift-^ and now I'm just a key combo away from synchronizing files on the remote server. What an awesome program ... :)

1 comment to Custom TextMate commands for ruby and scp

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">