Skip to content

Instantly share code, notes, and snippets.

@danlucraft
Created January 27, 2011 09:30
Show Gist options
  • Save danlucraft/798288 to your computer and use it in GitHub Desktop.
Save danlucraft/798288 to your computer and use it in GitHub Desktop.
handy script for rsyncing between machines
require 'rubygems'
require 'fsevents'
require 'fileutils'
STDOUT.sync = true
project = ARGV[0] || 'skweb'
options = {
:directory_to_watch => "/Users/danlucraft/Songkick/#{project}",
:remote_host => 'of1-dev-dan',
:remote_dir => "development/#{project}"
}
def sync(options)
start = Time.now
cmd = "rsync -varx --delete -e ssh --exclude='log/*' --exclude='*.yml.201*' --exclude='.redcar' --exclude='.git' --exclude='tmp/*' --exclude='*.css' #{options[:directory_to_watch]}/ #{options[:remote_host]}:#{options[:remote_dir]}/"
puts cmd
puts `#{cmd}`
puts "Synced in "
puts "#{sprintf('%.2f', Time.now - start)}s"
$0 = "Last #{Time.now.strftime("%X")}"
puts $0
end
sync(options)
FileUtils.cd(options[:directory_to_watch]) do
stream = FSEvents::Stream.watch(options[:directory_to_watch], :latency => 2.5) do
sync(options)
end
stream.run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment