watchdir 1.0.2 → 1.0.4
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/README.rdoc +17 -1
- data/VERSION +1 -1
- data/bin/watchdir +97 -1
- data/watchdir.gemspec +5 -5
- metadata +10 -12
- data/bin/watchdir.rb +0 -98
data/README.rdoc
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
= watchdir
|
2
2
|
|
3
|
-
|
3
|
+
Command for watching to multiple files.
|
4
|
+
|
5
|
+
== Install
|
6
|
+
|
7
|
+
sudo gem install watchdir
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
Usage: watchdir [options]
|
12
|
+
--help show this message
|
13
|
+
-e, --extensions=EXT1,EXT2... comma separated extention(s)
|
14
|
+
-c, --command=COMMAND execute when updated
|
15
|
+
-s, --sleep=SEC default 2 sec.
|
16
|
+
-d, --dir=DIR1,DIR2... comma separated directories
|
17
|
+
-f, --flush
|
18
|
+
--growl
|
19
|
+
--debug debug mode
|
4
20
|
|
5
21
|
== Contributing to watchdir
|
6
22
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.4
|
data/bin/watchdir
CHANGED
@@ -1,2 +1,98 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# $Id: watchdir,v 1.6 2009/03/01 10:39:36 tumf Exp $
|
3
|
+
# e.g.1:
|
4
|
+
# watchdir -e php,yaml,ini -s 2 -c "symfony sync stage go"
|
5
|
+
# e.g.2:
|
6
|
+
# watchdir -e php -c "php -l $$" -f
|
7
|
+
#
|
8
|
+
require 'pp'
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
sleep_sec = 2
|
12
|
+
command = false
|
13
|
+
glob_pattern = "./**/*"
|
14
|
+
$debug = false
|
15
|
+
extensions = []
|
16
|
+
directories = []
|
17
|
+
directory = "."
|
18
|
+
$flush = false
|
19
|
+
$growl = false
|
20
|
+
|
21
|
+
opt = OptionParser.new
|
22
|
+
opt.on('--help', 'show this message') { puts opt; exit }
|
23
|
+
opt.on('-e EXT1,EXT2...',"--extensions=EXT1,EXT2...",
|
24
|
+
"comma separated extention(s)"){ |v|
|
25
|
+
v.split(',').each{ |e| extensions << "*." + e }
|
26
|
+
}
|
27
|
+
opt.on('-c COMMAND','--command=COMMAND','execute when updated'){ |v| command = v}
|
28
|
+
opt.on('-s SEC','--sleep=SEC',"default #{sleep_sec} sec."){|v| sleep_sec = v.to_i}
|
29
|
+
opt.on('-d DIR1,DIR2...','--dir=DIR1,DIR2...',
|
30
|
+
"comma separated directories"){ |v|
|
31
|
+
directories = v.split(',') }
|
32
|
+
|
33
|
+
opt.on('-f','--flush'){ |v| $flush = true }
|
34
|
+
opt.on('--growl'){ |v| $growl = true }
|
35
|
+
|
36
|
+
opt.on('--debug','debug mode'){ |v| $debug = true }
|
37
|
+
|
38
|
+
opt.parse!(ARGV)
|
39
|
+
patterns = []
|
40
|
+
if directories.size > 0
|
41
|
+
directories.each do |d|
|
42
|
+
patterns <<
|
43
|
+
extensions.collect{ |e| [d,'**',e].join('/') }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
p patterns if $debug
|
47
|
+
|
48
|
+
glob_pattern = patterns.join("\0") if patterns.size > 0
|
49
|
+
p glob_pattern if $debug
|
50
|
+
|
51
|
+
watch_list = Hash.new
|
52
|
+
watch_list.default = 0
|
53
|
+
last_watch_list = false
|
54
|
+
mode = :all
|
55
|
+
mode = :each if command =~ /\$\$/
|
56
|
+
|
57
|
+
def command_exec command
|
58
|
+
puts("\033[2J") if $flush
|
59
|
+
puts("@" + Time.now.to_s)
|
60
|
+
if $growl
|
61
|
+
message = `#{command}`
|
62
|
+
unless message == @last_message
|
63
|
+
system("growlnotify -t '%s' -m '%s'" % [command,message])
|
64
|
+
end
|
65
|
+
@last_message = message
|
66
|
+
puts(message)
|
67
|
+
else
|
68
|
+
system(command)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
begin
|
73
|
+
while true
|
74
|
+
watch_list.clear
|
75
|
+
Dir.glob(glob_pattern).each do |file|
|
76
|
+
watch_list[file] = File.mtime(file)
|
77
|
+
end
|
78
|
+
# p watch_list if $debug
|
79
|
+
last_watch_list = watch_list.clone unless last_watch_list
|
80
|
+
updated = false
|
81
|
+
watch_list.each do |file,time|
|
82
|
+
if last_watch_list[file] != time
|
83
|
+
pp file if $debug
|
84
|
+
if mode == :each
|
85
|
+
command_exec command.gsub(/\$\$/,file)
|
86
|
+
end
|
87
|
+
updated = true
|
88
|
+
end
|
89
|
+
end
|
90
|
+
if mode == :all and updated
|
91
|
+
if last_watch_list and command
|
92
|
+
command_exec command
|
93
|
+
end
|
94
|
+
end
|
95
|
+
last_watch_list = watch_list.clone
|
96
|
+
sleep(sleep_sec)
|
97
|
+
end
|
98
|
+
end
|
data/watchdir.gemspec
CHANGED
@@ -5,14 +5,15 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{watchdir}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Yoshihiro TAKAHARA"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-17}
|
13
|
+
s.default_executable = %q{watchdir}
|
13
14
|
s.description = %q{ watch command for multiple files. }
|
14
15
|
s.email = %q{y.takahara@gmail.com}
|
15
|
-
s.executables = ["watchdir
|
16
|
+
s.executables = ["watchdir"]
|
16
17
|
s.extra_rdoc_files = [
|
17
18
|
"LICENSE.txt",
|
18
19
|
"README.rdoc"
|
@@ -24,7 +25,6 @@ Gem::Specification.new do |s|
|
|
24
25
|
"Rakefile",
|
25
26
|
"VERSION",
|
26
27
|
"bin/watchdir",
|
27
|
-
"bin/watchdir.rb",
|
28
28
|
"lib/watchdir.rb",
|
29
29
|
"spec/spec_helper.rb",
|
30
30
|
"spec/watchdir_spec.rb",
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.homepage = %q{http://github.com/tumf/watchdir}
|
34
34
|
s.licenses = ["MIT"]
|
35
35
|
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = %q{1.4.
|
36
|
+
s.rubygems_version = %q{1.4.2}
|
37
37
|
s.summary = %q{Watchdir is a command for watching change of files to execute command.}
|
38
38
|
s.test_files = [
|
39
39
|
"spec/spec_helper.rb",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watchdir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 4
|
10
|
+
version: 1.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yoshihiro TAKAHARA
|
@@ -15,10 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-01-17 00:00:00 +09:00
|
19
|
+
default_executable: watchdir
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
+
type: :development
|
22
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
24
|
none: false
|
24
25
|
requirements:
|
@@ -33,8 +34,8 @@ dependencies:
|
|
33
34
|
requirement: *id001
|
34
35
|
prerelease: false
|
35
36
|
name: rspec
|
36
|
-
type: :development
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
+
type: :development
|
38
39
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
41
|
requirements:
|
@@ -49,8 +50,8 @@ dependencies:
|
|
49
50
|
requirement: *id002
|
50
51
|
prerelease: false
|
51
52
|
name: bundler
|
52
|
-
type: :development
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
+
type: :development
|
54
55
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
56
|
none: false
|
56
57
|
requirements:
|
@@ -65,8 +66,8 @@ dependencies:
|
|
65
66
|
requirement: *id003
|
66
67
|
prerelease: false
|
67
68
|
name: jeweler
|
68
|
-
type: :development
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
+
type: :development
|
70
71
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
72
|
none: false
|
72
73
|
requirements:
|
@@ -79,11 +80,9 @@ dependencies:
|
|
79
80
|
requirement: *id004
|
80
81
|
prerelease: false
|
81
82
|
name: rcov
|
82
|
-
type: :development
|
83
83
|
description: " watch command for multiple files. "
|
84
84
|
email: y.takahara@gmail.com
|
85
85
|
executables:
|
86
|
-
- watchdir.rb
|
87
86
|
- watchdir
|
88
87
|
extensions: []
|
89
88
|
|
@@ -97,7 +96,6 @@ files:
|
|
97
96
|
- Rakefile
|
98
97
|
- VERSION
|
99
98
|
- bin/watchdir
|
100
|
-
- bin/watchdir.rb
|
101
99
|
- lib/watchdir.rb
|
102
100
|
- spec/spec_helper.rb
|
103
101
|
- spec/watchdir_spec.rb
|
@@ -132,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
130
|
requirements: []
|
133
131
|
|
134
132
|
rubyforge_project:
|
135
|
-
rubygems_version: 1.4.
|
133
|
+
rubygems_version: 1.4.2
|
136
134
|
signing_key:
|
137
135
|
specification_version: 3
|
138
136
|
summary: Watchdir is a command for watching change of files to execute command.
|
data/bin/watchdir.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# $Id: watchdir,v 1.6 2009/03/01 10:39:36 tumf Exp $
|
3
|
-
# e.g.1:
|
4
|
-
# watchdir -e php,yaml,ini -s 2 -c "symfony sync stage go"
|
5
|
-
# e.g.2:
|
6
|
-
# watchdir -e php -c "php -l $$" -f
|
7
|
-
#
|
8
|
-
require 'pp'
|
9
|
-
require 'optparse'
|
10
|
-
|
11
|
-
sleep_sec = 2
|
12
|
-
command = false
|
13
|
-
glob_pattern = "./**/*"
|
14
|
-
$debug = false
|
15
|
-
extensions = []
|
16
|
-
directories = []
|
17
|
-
directory = "."
|
18
|
-
$flush = false
|
19
|
-
$growl = false
|
20
|
-
|
21
|
-
opt = OptionParser.new
|
22
|
-
opt.on('--help', 'show this message') { puts opt; exit }
|
23
|
-
opt.on('-e EXT1,EXT2...',"--extensions=EXT1,EXT2...",
|
24
|
-
"comma separated extention(s)"){ |v|
|
25
|
-
v.split(',').each{ |e| extensions << "*." + e }
|
26
|
-
}
|
27
|
-
opt.on('-c COMMAND','--command=COMMAND','execute when updated'){ |v| command = v}
|
28
|
-
opt.on('-s SEC','--sleep=SEC',"default #{sleep_sec} sec."){|v| sleep_sec = v.to_i}
|
29
|
-
opt.on('-d DIR1,DIR2...','--dir=DIR1,DIR2...',
|
30
|
-
"comma separated directories"){ |v|
|
31
|
-
directories = v.split(',') }
|
32
|
-
|
33
|
-
opt.on('-f','--flush'){ |v| $flush = true }
|
34
|
-
opt.on('--growl'){ |v| $growl = true }
|
35
|
-
|
36
|
-
opt.on('--debug','debug mode'){ |v| $debug = true }
|
37
|
-
|
38
|
-
opt.parse!(ARGV)
|
39
|
-
patterns = []
|
40
|
-
if directories.size > 0
|
41
|
-
directories.each do |d|
|
42
|
-
patterns <<
|
43
|
-
extensions.collect{ |e| [d,'**',e].join('/') }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
p patterns if $debug
|
47
|
-
|
48
|
-
glob_pattern = patterns.join("\0") if patterns.size > 0
|
49
|
-
p glob_pattern if $debug
|
50
|
-
|
51
|
-
watch_list = Hash.new
|
52
|
-
watch_list.default = 0
|
53
|
-
last_watch_list = false
|
54
|
-
mode = :all
|
55
|
-
mode = :each if command =~ /\$\$/
|
56
|
-
|
57
|
-
def command_exec command
|
58
|
-
puts("\033[2J") if $flush
|
59
|
-
puts("@" + Time.now.to_s)
|
60
|
-
if $growl
|
61
|
-
message = `#{command}`
|
62
|
-
unless message == @last_message
|
63
|
-
system("growlnotify -t '%s' -m '%s'" % [command,message])
|
64
|
-
end
|
65
|
-
@last_message = message
|
66
|
-
puts(message)
|
67
|
-
else
|
68
|
-
system(command)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
begin
|
73
|
-
while true
|
74
|
-
watch_list.clear
|
75
|
-
Dir.glob(glob_pattern).each do |file|
|
76
|
-
watch_list[file] = File.mtime(file)
|
77
|
-
end
|
78
|
-
# p watch_list if $debug
|
79
|
-
last_watch_list = watch_list.clone unless last_watch_list
|
80
|
-
updated = false
|
81
|
-
watch_list.each do |file,time|
|
82
|
-
if last_watch_list[file] != time
|
83
|
-
pp file if $debug
|
84
|
-
if mode == :each
|
85
|
-
command_exec command.gsub(/\$\$/,file)
|
86
|
-
end
|
87
|
-
updated = true
|
88
|
-
end
|
89
|
-
end
|
90
|
-
if mode == :all and updated
|
91
|
-
if last_watch_list and command
|
92
|
-
command_exec command
|
93
|
-
end
|
94
|
-
end
|
95
|
-
last_watch_list = watch_list.clone
|
96
|
-
sleep(sleep_sec)
|
97
|
-
end
|
98
|
-
end
|