From 0a380c6af045f109798befd62de3cb170a6870b5 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 2 May 2012 22:54:11 -0400 Subject: [PATCH] cross platform --- Gemfile | 10 +++++++++- bin/unison-watch | 27 ++++++++++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index e44a59d..854b0f7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,15 @@ source :rubygems gem 'qtbindings' -gem 'rb-fsevent' +require 'rbconfig' + +case RbConfig::CONFIG['host_os'] +when /darwin/ + gem 'rb-fsevent' +when /linux/ + gem 'rb-inotify' +end + gem 'atomic' gem 'daemons' diff --git a/bin/unison-watch b/bin/unison-watch index 00cc23f..d78480b 100755 --- a/bin/unison-watch +++ b/bin/unison-watch @@ -3,15 +3,12 @@ require 'bundler/setup' require 'Qt4' -require 'rb-fsevent' require 'thread' require 'atomic' require 'daemons' - ENV['PROFILE'] ||= 'default' - TRANSFER_LOG = '~/unison.log' SYNC_CHECK_COUNT = 600 SYNC_CHECK_TIME = 0.1 @@ -46,7 +43,7 @@ def check @current_icon = 'idle' end - system %{bash -c 'unison -batch default'} + system %{bash -c 'unison -log -logfile #{TRANSFER_LOG} -batch #{ENV['PROFILE']}'} animation[:done] = true @@ -94,15 +91,31 @@ class UnisonProfile end profile = UnisonProfile.new +require 'rbconfig' watcher = Thread.new do while !Thread.current[:app]; sleep 0.1; end begin - watch = FSEvent.new - watch.watch Thread.current[:paths], :latency => 0.25 do |directories| - Thread.current[:app] << directories + watch = nil + + case RbConfig::CONFIG['host_os'] + when /darwin/ + require 'rb-fsevent' + watch = FSEvent.new + watch.watch Thread.current[:paths], :latency => 0.25 do |directories| + Thread.current[:app] << directories + end + when /linux/ + require 'rb-inotify' + watch = INotify::Notifier.new + Thread.current[:paths].each do |path| + notifier.watch path, :recursive, :modify, :create, :delete do |event| + Thread.current[:app] << event.absolute_name + end + end end + watch.run rescue => e puts e.message