fswatch 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # fswatch
2
- A super trivial Ruby script for triggering a command on file system change in OS X.
2
+ A trivial Ruby script for triggering a command on file system change in OS X.
3
3
 
4
4
  ## Installation
5
5
 
@@ -11,4 +11,32 @@ The point was mainly to shove this into gemcutter so it's easy to deploy:
11
11
 
12
12
  On file system change execute `ls -l`:
13
13
 
14
- $ fswatch ls -l
14
+ $ fswatch ls -l
15
+
16
+ Watch a specific path:
17
+
18
+ $ fswatch -d / ls -l
19
+
20
+ Wait at least 5 seconds before refreshing using deferral:
21
+
22
+ $ fswatch -t5 ls -l
23
+
24
+ If the command is long running and you want to forcibly restart it on file system change:
25
+
26
+ $ fswatch -x ls -l
27
+
28
+ If you want to pass the paths which have changed as a parameter to the command:
29
+
30
+ $ fswatch -p echo
31
+
32
+ If you want to place the paths somewhere other than at the end, use the `@fspaths` token:
33
+
34
+ $ fswatch -p "echo @fspaths | wc -l"
35
+
36
+ You can also use `@fspathscolon` for colon-separated paths and `@fspatchcomma` for comma-separated paths.
37
+
38
+ ## Examples
39
+
40
+ Automatically rsync on changes:
41
+
42
+ $ fswatch -t 5 "rsync -av . devbox:/devfolder-on-devbox/"
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  # specify any dependencies here; for example:
22
22
  # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
24
23
  s.add_runtime_dependency 'rb-fsevent'
24
+ s.add_runtime_dependency 'trollop'
25
25
  s.add_runtime_dependency 'term-ansicolor'
26
26
  end
@@ -1,16 +1,55 @@
1
1
  require 'fswatch/version'
2
2
 
3
+ require 'rubygems'
4
+ require 'trollop'
3
5
  require 'rb-fsevent'
4
6
  require 'term/ansicolor'
5
7
 
6
8
  include Term::ANSIColor
7
9
 
8
10
  module FSWatch
9
-
10
- fsevent = FSEvent.new
11
- fsevent.watch Dir.pwd do |directories|
11
+
12
+ opts = Trollop::options do
13
+ version "fswatch - #{VERSION} (c) 2012 w.k.macura - Released under BSD license"
14
+ banner <<-EOS
15
+ A utility for triggering a command on file system change.
16
+ EOS
17
+
18
+ opt :dir, "the directory to watch", :default => '.'
19
+ opt :throttle, "only allow one fsevent in the given amount of seconds", :default => 1
20
+ opt :kill, "forcibly restart the command if it's still running during an fs trigger", :short => :x
21
+ opt :paths, "append the changed paths when calling the command"
22
+ end
23
+
24
+ if opts[:dir] == '.'
25
+ dir = Dir.pwd
26
+ else
27
+ dir = opts[:dir]
28
+ end
29
+
30
+ fsevent = FSEvent.new
31
+ fsevent.watch dir, { :latency => opts[:throttle], :no_defer => true } do |directories|
12
32
  print red, "\n\n--- Changed: ", bold, blue, directories.inspect, reset, "\n"
13
- system(ARGV.join(' '))
33
+ if @processPid
34
+ status = Process.wait(@processPid, Process::WNOHANG)
35
+ if status == nil
36
+ print red, "!!! Killing #{@processPid}", reset, "\n"
37
+ Process.kill("KILL", @processPid)
38
+ end
39
+ end
40
+
41
+ command = ARGV.join(' ')
42
+ command.sub!("@fspathscolon", directories.join(':'))
43
+ command.sub!("@fspathscomma", directories.join(','))
44
+ command.sub!("@fspaths", directories.join(' '))
45
+
46
+ if opts[:paths]
47
+ command << ' ' << directories.join(' ')
48
+ end
49
+
50
+ @processPid = fork {
51
+ system(command)
52
+ }
14
53
  end
15
54
 
16
55
  fsevent.run
@@ -1,3 +1,3 @@
1
1
  module Fswatch
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fswatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-14 00:00:00.000000000Z
12
+ date: 2012-01-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rb-fsevent
16
- requirement: &70326022078700 !ruby/object:Gem::Requirement
16
+ requirement: &70115501893640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70326022078700
24
+ version_requirements: *70115501893640
25
+ - !ruby/object:Gem::Dependency
26
+ name: trollop
27
+ requirement: &70115501893220 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70115501893220
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: term-ansicolor
27
- requirement: &70326022078160 !ruby/object:Gem::Requirement
38
+ requirement: &70115501892800 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,7 +43,7 @@ dependencies:
32
43
  version: '0'
33
44
  type: :runtime
34
45
  prerelease: false
35
- version_requirements: *70326022078160
46
+ version_requirements: *70115501892800
36
47
  description: ''
37
48
  email:
38
49
  - wiktor@tumblr.com