fswatch 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fswatch.rb +35 -25
- data/lib/fswatch/version.rb +1 -1
- metadata +7 -7
data/lib/fswatch.rb
CHANGED
@@ -9,48 +9,58 @@ include Term::ANSIColor
|
|
9
9
|
|
10
10
|
module FSWatch
|
11
11
|
|
12
|
-
|
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
|
+
def FSWatch.run_command(directories)
|
32
13
|
print red, "\n\n--- Changed: ", bold, blue, directories.inspect, reset, "\n"
|
33
14
|
if @processPid
|
34
15
|
status = Process.wait(@processPid, Process::WNOHANG)
|
35
16
|
if status == nil
|
36
|
-
|
37
|
-
|
17
|
+
print red, "!!! Killing #{@processPid}", reset, "\n"
|
18
|
+
Process.kill("KILL", @processPid)
|
38
19
|
end
|
39
|
-
|
20
|
+
end
|
40
21
|
|
41
22
|
command = ARGV.join(' ')
|
42
23
|
command.sub!("@fspathscolon", directories.join(':'))
|
43
24
|
command.sub!("@fspathscomma", directories.join(','))
|
44
25
|
command.sub!("@fspaths", directories.join(' '))
|
45
26
|
|
46
|
-
if opts[:paths]
|
47
|
-
|
27
|
+
if @opts[:paths]
|
28
|
+
command << ' ' << directories.join(' ')
|
48
29
|
end
|
49
30
|
|
50
31
|
@processPid = fork {
|
51
32
|
system(command)
|
52
33
|
}
|
53
34
|
end
|
35
|
+
|
36
|
+
|
37
|
+
@opts = Trollop::options do
|
38
|
+
version "fswatch - #{VERSION} (c) 2012 w.k.macura - Released under BSD license"
|
39
|
+
banner <<-EOS
|
40
|
+
A utility for triggering a command on file system change.
|
41
|
+
EOS
|
42
|
+
|
43
|
+
opt :start, "whether the command should be executed immediately on start", :default => true
|
44
|
+
opt :dir, "the directory to watch", :default => '.'
|
45
|
+
opt :throttle, "only allow one fsevent in the given amount of seconds", :default => 1
|
46
|
+
opt :kill, "forcibly restart the command if it's still running during an fs trigger", :short => :x
|
47
|
+
opt :paths, "append the changed paths when calling the command"
|
48
|
+
end
|
49
|
+
|
50
|
+
if @opts[:dir] == '.'
|
51
|
+
dir = Dir.pwd
|
52
|
+
else
|
53
|
+
dir = @opts[:dir]
|
54
|
+
end
|
55
|
+
|
56
|
+
if @opts[:start]
|
57
|
+
run_command([])
|
58
|
+
end
|
59
|
+
|
60
|
+
fsevent = FSEvent.new
|
61
|
+
fsevent.watch dir, { :latency => @opts[:throttle], :no_defer => true } do |directories|
|
62
|
+
run_command(directories)
|
63
|
+
end
|
54
64
|
|
55
65
|
fsevent.run
|
56
66
|
end
|
data/lib/fswatch/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-26 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rb-fsevent
|
16
|
-
requirement: &
|
16
|
+
requirement: &70152326580060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70152326580060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: trollop
|
27
|
-
requirement: &
|
27
|
+
requirement: &70152326579400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70152326579400
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: term-ansicolor
|
38
|
-
requirement: &
|
38
|
+
requirement: &70152326578160 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70152326578160
|
47
47
|
description: ''
|
48
48
|
email:
|
49
49
|
- wiktor@tumblr.com
|