Created
June 25, 2014 09:16
-
-
Save jemiam/a14abfbb8bcdd25c5ab8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "optparse" | |
def usage | |
puts "usage: #{File.basename(__FILE__)} SRC DST [ -e EXCLUDE ] [ --use-sudo ]" | |
end | |
src = ARGV.shift | |
unless src | |
usage | |
exit 1 | |
end | |
src = File.join(src, "/") | |
dst = ARGV.shift | |
unless dst | |
usage | |
exit 1 | |
end | |
dst = File.join(dst, "/") | |
excludes = [] | |
use_sudo = false | |
rsync_path = "rsync" | |
OptionParser.new.tap do |opt| | |
opt.on("-e EXCLUDE") { |v| excludes << v } | |
opt.on("--use-sudo") { |v| rsync_path = "sudo #{rsync_path}" } | |
opt.parse!(ARGV) | |
end | |
exclude_options = excludes.map { |s| "--exclude #{s}" }.join(" ") | |
rsync_command = %Q(rsync -avz --no-o --no-g -e "ssh" --rsync-path=#{rsync_path} --delete #{exclude_options} #{src} #{dst}) | |
monitor_command = case RUBY_PLATFORM | |
when /darwin/ | |
"fswatch -o #{src} | xargs -n1 -I{} #{rsync_command}" | |
when /linux/ | |
<<SCRIPT | |
while inotifywait -e modify -e create -e move -e delete --exclude "\..*\.sw[pox].*" -r #{src}; do | |
#{rsync_command} | |
done | |
SCRIPT | |
end | |
`#{monitor_command}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment