watch_and_do 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/watch_and_do +13 -4
- metadata +1 -1
data/bin/watch_and_do
CHANGED
@@ -9,6 +9,11 @@ Example: watch_and_do /tmp/ss js,coffee,rb /tmp/do.rb
|
|
9
9
|
Example: watch_and_do . coffee ./rebuild.sh
|
10
10
|
"
|
11
11
|
|
12
|
+
opts.on( '-v', '--version', 'Displays this screen' ) do
|
13
|
+
puts eval(File.new("./../watch_and_do.gemspec", "r").read).version
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
12
17
|
opts.on( '-h', '--help', 'Displays this screen' ) do
|
13
18
|
puts opts
|
14
19
|
exit
|
@@ -33,8 +38,7 @@ if ARGV.size == 3
|
|
33
38
|
|
34
39
|
dir = File.new get_full_path(ARGV[0])
|
35
40
|
extensions = ARGV[1].split(',')
|
36
|
-
script = ARGV[2]
|
37
|
-
|
41
|
+
script = File.new get_full_path(ARGV[2])
|
38
42
|
|
39
43
|
# validation (path + script exist)
|
40
44
|
if !File::exists? dir
|
@@ -42,10 +46,14 @@ if ARGV.size == 3
|
|
42
46
|
puts "invalid directory name"
|
43
47
|
end
|
44
48
|
|
49
|
+
script_path = File.expand_path script
|
50
|
+
dir_path = File.expand_path dir
|
51
|
+
|
45
52
|
if valid
|
53
|
+
puts "\nNow watching #{dir_path} and executing #{script_path}"
|
46
54
|
# start watch + call script on modified file
|
47
55
|
while true do
|
48
|
-
line = %x[inotifywait -e modify -q -r #{
|
56
|
+
line = %x[inotifywait -e modify -q -r #{dir_path}]
|
49
57
|
|
50
58
|
words = line.split(' MODIFY ')
|
51
59
|
|
@@ -54,7 +62,8 @@ if ARGV.size == 3
|
|
54
62
|
|
55
63
|
extensions.each do |ext|
|
56
64
|
if filename.end_with? ext
|
57
|
-
puts
|
65
|
+
puts "#{script_path} #{filename}"
|
66
|
+
puts %x[#{script_path} #{filename} &]
|
58
67
|
break
|
59
68
|
end
|
60
69
|
end
|