Created
February 6, 2012 04:42
-
-
Save gcatlin/1749686 to your computer and use it in GitHub Desktop.
Automatic rsync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rb-fsevent' | |
require 'open3' | |
ignore_dirs = ['.git', '.hg', '.svn'] | |
def popen cmd | |
Open3.popen3 cmd do |stdin, stdout, stderr| | |
stdout.read.split("\n").each do |line| | |
puts "#{Time.new} #{line}" | |
end | |
end | |
end | |
src = File.absolute_path ARGV[0] unless !File.directory? ARGV[0] | |
src << '/' unless src.end_with? '/' | |
dst = ARGV[1].dup | |
dst << '/' unless dst.end_with? '/' | |
rsync_opts = "-dlptgoDvz" # --delete" | |
rsync_excludes = ignore_dirs.collect {|d| "--exclude=" + d}.join(" ") | |
popen "rsync #{rsync_opts} #{rsync_excludes} #{src} #{dst}" | |
ignore_dirs.collect! {|d| "/" + d + "/"} | |
fsevent = FSEvent.new | |
fsevent.watch src do |dirs| | |
dirs.each do |dir| | |
unless ignore_dirs.any? {|d| dir.include? d} | |
dir.slice! src | |
popen "rsync #{rsync_opts} #{rsync_excludes} #{src}#{dir} #{dst}#{dir}" | |
end | |
end | |
end | |
fsevent.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment