watchdir 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +60 -0
- data/VERSION +1 -0
- data/bin/watchdir +2 -0
- data/bin/watchdir.rb +98 -0
- data/lib/watchdir.rb +0 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/watchdir_spec.rb +7 -0
- data/watchdir.gemspec +74 -0
- metadata +142 -0
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.3.0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Yoshihiro TAKAHARA
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= watchdir
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to watchdir
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Yoshihiro TAKAHARA. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "watchdir"
|
16
|
+
gem.homepage = "http://github.com/tumf/watchdir"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{ Watchdir is a command for watching change of files to execute command. }
|
19
|
+
gem.description = %Q{
|
20
|
+
Usage: watchdir [options]
|
21
|
+
--help show this message
|
22
|
+
-e, --extensions=EXT1,EXT2... comma separated extention(s)
|
23
|
+
-c, --command=COMMAND execute when updated
|
24
|
+
-s, --sleep=SEC default 2 sec.
|
25
|
+
-d, --dir=DIR1,DIR2... comma separated directories
|
26
|
+
-f, --flush
|
27
|
+
--growl
|
28
|
+
--debug debug mode
|
29
|
+
}
|
30
|
+
gem.email = "y.takahara@gmail.com"
|
31
|
+
gem.authors = ["Yoshihiro TAKAHARA"]
|
32
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
33
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
34
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
35
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
36
|
+
end
|
37
|
+
Jeweler::RubygemsDotOrgTasks.new
|
38
|
+
|
39
|
+
require 'rspec/core'
|
40
|
+
require 'rspec/core/rake_task'
|
41
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
42
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
43
|
+
end
|
44
|
+
|
45
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
46
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
47
|
+
spec.rcov = true
|
48
|
+
end
|
49
|
+
|
50
|
+
task :default => :spec
|
51
|
+
|
52
|
+
require 'rake/rdoctask'
|
53
|
+
Rake::RDocTask.new do |rdoc|
|
54
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
55
|
+
|
56
|
+
rdoc.rdoc_dir = 'rdoc'
|
57
|
+
rdoc.title = "watchdir #{version}"
|
58
|
+
rdoc.rdoc_files.include('README*')
|
59
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
60
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/bin/watchdir
ADDED
data/bin/watchdir.rb
ADDED
@@ -0,0 +1,98 @@
|
|
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
|
data/lib/watchdir.rb
ADDED
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'watchdir'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
data/watchdir.gemspec
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{watchdir}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Yoshihiro TAKAHARA"]
|
12
|
+
s.date = %q{2011-01-12}
|
13
|
+
s.description = %q{
|
14
|
+
Usage: watchdir [options]
|
15
|
+
--help show this message
|
16
|
+
-e, --extensions=EXT1,EXT2... comma separated extention(s)
|
17
|
+
-c, --command=COMMAND execute when updated
|
18
|
+
-s, --sleep=SEC default 2 sec.
|
19
|
+
-d, --dir=DIR1,DIR2... comma separated directories
|
20
|
+
-f, --flush
|
21
|
+
--growl
|
22
|
+
--debug debug mode
|
23
|
+
}
|
24
|
+
s.email = %q{y.takahara@gmail.com}
|
25
|
+
s.executables = ["watchdir.rb", "watchdir"]
|
26
|
+
s.extra_rdoc_files = [
|
27
|
+
"LICENSE.txt",
|
28
|
+
"README.rdoc"
|
29
|
+
]
|
30
|
+
s.files = [
|
31
|
+
"Gemfile",
|
32
|
+
"LICENSE.txt",
|
33
|
+
"README.rdoc",
|
34
|
+
"Rakefile",
|
35
|
+
"VERSION",
|
36
|
+
"bin/watchdir",
|
37
|
+
"bin/watchdir.rb",
|
38
|
+
"lib/watchdir.rb",
|
39
|
+
"spec/spec_helper.rb",
|
40
|
+
"spec/watchdir_spec.rb",
|
41
|
+
"watchdir.gemspec"
|
42
|
+
]
|
43
|
+
s.homepage = %q{http://github.com/tumf/watchdir}
|
44
|
+
s.licenses = ["MIT"]
|
45
|
+
s.require_paths = ["lib"]
|
46
|
+
s.rubygems_version = %q{1.4.1}
|
47
|
+
s.summary = %q{Watchdir is a command for watching change of files to execute command.}
|
48
|
+
s.test_files = [
|
49
|
+
"spec/spec_helper.rb",
|
50
|
+
"spec/watchdir_spec.rb"
|
51
|
+
]
|
52
|
+
|
53
|
+
if s.respond_to? :specification_version then
|
54
|
+
s.specification_version = 3
|
55
|
+
|
56
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
58
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
60
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
63
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
64
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
65
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
66
|
+
end
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
71
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: watchdir
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Yoshihiro TAKAHARA
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-12 00:00:00 +09:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 3
|
31
|
+
- 0
|
32
|
+
version: 2.3.0
|
33
|
+
requirement: *id001
|
34
|
+
prerelease: false
|
35
|
+
name: rspec
|
36
|
+
type: :development
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 23
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 0
|
47
|
+
- 0
|
48
|
+
version: 1.0.0
|
49
|
+
requirement: *id002
|
50
|
+
prerelease: false
|
51
|
+
name: bundler
|
52
|
+
type: :development
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 7
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 5
|
63
|
+
- 2
|
64
|
+
version: 1.5.2
|
65
|
+
requirement: *id003
|
66
|
+
prerelease: false
|
67
|
+
name: jeweler
|
68
|
+
type: :development
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirement: *id004
|
80
|
+
prerelease: false
|
81
|
+
name: rcov
|
82
|
+
type: :development
|
83
|
+
description: "\n\
|
84
|
+
Usage: watchdir [options]\n --help show this message\n -e, --extensions=EXT1,EXT2... comma separated extention(s)\n -c, --command=COMMAND execute when updated\n -s, --sleep=SEC default 2 sec.\n -d, --dir=DIR1,DIR2... comma separated directories\n -f, --flush\n --growl\n --debug debug mode\n "
|
85
|
+
email: y.takahara@gmail.com
|
86
|
+
executables:
|
87
|
+
- watchdir.rb
|
88
|
+
- watchdir
|
89
|
+
extensions: []
|
90
|
+
|
91
|
+
extra_rdoc_files:
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.rdoc
|
94
|
+
files:
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.rdoc
|
98
|
+
- Rakefile
|
99
|
+
- VERSION
|
100
|
+
- bin/watchdir
|
101
|
+
- bin/watchdir.rb
|
102
|
+
- lib/watchdir.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
- spec/watchdir_spec.rb
|
105
|
+
- watchdir.gemspec
|
106
|
+
has_rdoc: true
|
107
|
+
homepage: http://github.com/tumf/watchdir
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
hash: 3
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
version: "0"
|
133
|
+
requirements: []
|
134
|
+
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.4.1
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: Watchdir is a command for watching change of files to execute command.
|
140
|
+
test_files:
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
- spec/watchdir_spec.rb
|