Skip to content

Instantly share code, notes, and snippets.

@karptonite
Last active December 15, 2015 13:29
Show Gist options
  • Save karptonite/5267877 to your computer and use it in GitHub Desktop.
Save karptonite/5267877 to your computer and use it in GitHub Desktop.
My setup for using rsync to work locally on a remote server
My setup has Cmd-S and Cmd-Shift-S remapped to run the following AFTER saving:
if [ $TM_RSYNC_SOURCE ]
then
rsync -e "ssh" -avz --exclude '.DS_Store' --exclude '.FBCLockFolder' --exclude 'templates_c/' --exclude 'css/compiled/' --exclude '*.git' --exclude '*.out' --exclude '*.mlog' --delete "$TM_RSYNC_SOURCE" "$TM_RSYNC_DEST"
fi
the variables are project-specific Textmate variables--I'm sure there must be a way to
do something similar with Sublime--I just haven't tried yet. For me, for example,
TM_RSYNC_DST is karp@ourdevsystem.com:/var/www/karp/
and TM_RSYNC_SRC is /Users/karp/Documents/git/bgg/
Mind the trailing slashes! rsync is particular about that. Also, notice the --delete--that means it will
delete anything in the remote location taht is not local, so be careful!
I recommend first running it with the --dry-run option, which does just what it sounds like.
One other trick is that I keep a persistent ssh connection open to make the syncing faster.
You do it by putting the following in your config file in your .ssh directory:
Host *
ControlMaster auto
ControlPath ~/.ssh/socket-%r@%h:%p
AND you have to keep an ssh connection open to your remote system in a terminal. I do that anyway,
for running phpunit, etc.
The only problem with this is that sometimes you have to go to your .ssh directory to manually
delete a socket if it doesn't close properly--but usually, it works fine, and makes rsync
much faster.
This allows me to keep my git repository locally as well, which is particularly convenient if you want
to use a program like sourcetree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment