TextMate remote sync bundle
This TextMate bundle will let you keep a directory on a remote server in sync with your local work directory.
All you have to do, is these three things:
- Install the bundle in TextMate
- Add your ssh public key1 to
~/.ssh/authorized_keys
on the remote server you wish to copy your files to.
If you have a password on your key, then you need to add it to the Keychain usingssh-add -K
, once this is done OS X will use thessh-agent
to query the Keychain for your password. - Configure bundle settings for your project via the bundle menu.
The first time you call configure, a new config file will be generated for you with explaining comments.
Please note that it only works within projects as we need to have a directory to hold our .tm_sync.config
config file.
Configuration
To configure this bundle, bring up the Select Bundle Item
by pressing ^⌘T
and start typing configure
.
An item called Configure - Synchronize remote directory [rsync+ssh]
should appear at the top. Selecting that will generate a config file for you that looks something like this:
{% codeblock lang:bash %}
Change the configuration below to match your setup
You have to setup ssh public key authentication in order for this
to work, as we need to be able to copy stuff without entering a
password everytime.
REMOTE_HOST="your.server.tld" REMOTE_PORT="22" REMOTE_USER="username" REMOTE_PATH="/remote/directory"
Here you can parse options on to rsync
if you e.g. want to exclude files
RSYNC_OPTIONS="--exclude=.git --delete"
Use the rsync option below with caution, as it replaces the remote
directory with the contents of your project.
RSYNC_OPTIONS="--delete"
Use this option to run any command on the remote end after a
successful copy
REMOTE_POST_COMMAND="make && make install"
{% endcodeblock %}
Now you just need to change it to fit your needs.
Configuring ssh
The first half of the config deals with ssh
.
REMOTE_HOST
This is the host you want to upload your project toREMOTE_PORT
The portssh
will use to connect to - You rarely have to change this.REMOTE_USER
The username of the user on the remote host that should receive the files.REMOTE_PATH
The full path to the directory where your project files will be rsync'ed to. Note that this directory will be overwritten and any existing content will be removed if you specify2 the--delete
option.
Configuring rsync
When we sync the project to the remote host we pass the RSYNC_OPTIONS
to rsync
unchanged.
{% codeblock lang:bash %} rsync -v -zar --exclude=.tm_sync.config $RSYNC_OPTIONS
This means that you can pass any command line option you want to rsync. Want to exclude more files, just add an extra --exclude=file_to_exclude.txt
.
Configuring post commands
In version 1.1, I added the ability to run any command on the remote host after a successful rsync. You can use this to build and install or build and test your code on the remote host.
You have to create a one-liner with all the commands you want to run chained together by &&
like so:
{% codeblock lang:bash %} REMOTE_POST_COMMAND="make && make test"
Please note that the command will be run in a non-interactive shell and therefore might have a different set of environment variables that if you login normally via ssh.
Download
You can find the source on GitHub or just download the bundle here.
-
For more info on setting up your ssh keys please refer to this nice guide on github.com. ↩
-
You should always use the
--delete
option to ensure that the code you are using on the remote end is the same as the code you are viewing in TextMate. ↩