filewatcher 0.3.4 → 0.3.5
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.
- checksums.yaml +4 -4
- data/README.md +175 -0
- data/Rakefile +22 -39
- data/lib/filewatcher.rb +7 -6
- data/test/fixtures/file1.txt +1 -1
- data/test/fixtures/file2.txt +1 -1
- data/test/test_filewatcher.rb +47 -0
- metadata +44 -11
- data/README.rdoc +0 -147
- data/VERSION +0 -1
- data/test/filewatcher_spec.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 580b8d90d111cb7706b3c3a4f587bbb44ef3589c
|
4
|
+
data.tar.gz: b91ab8f3512252cda8da5a6e137f6919857df4e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a76f9a6b2153aae280c48357a32df976123da3c8f5f8a9e726812ab4a4b9cfe2292b2789b337da7b759d36b8962c373b7e372c27ce5fd5e8bfc891af8ceda307
|
7
|
+
data.tar.gz: 82e485c94aba35cae31403d8f9d043135bde656cd3a34b37b4d8abe31eed628bb74375b675ed027611b22b071aacb7f97cc73cd4aa513739b8c7d71e295a6364
|
data/README.md
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
Filewatcher
|
2
|
+
===========
|
3
|
+
|
4
|
+
[](http://travis-ci.org/judofyr/temple) [](https://gemnasium.com/judofyr/temple) [](https://codeclimate.com/github/judofyr/temple)
|
5
|
+
|
6
|
+
Lightweight filewatcher weighing less than 200 LoC. No dependencies or platform specific code.
|
7
|
+
Works everywhere. Monitors changes in the filesystem by polling. No config files needed to run.
|
8
|
+
|
9
|
+
Install
|
10
|
+
-------
|
11
|
+
|
12
|
+
Needs Ruby and Rubygems:
|
13
|
+
|
14
|
+
$ [sudo] gem install filewatcher
|
15
|
+
|
16
|
+
Command line utility
|
17
|
+
--------------------
|
18
|
+
|
19
|
+
Filewatcher scans the filesystem and execute shell commands when files are
|
20
|
+
changed.
|
21
|
+
|
22
|
+
Usage:
|
23
|
+
filewatcher [-i interval] "<filename>" "<shell command>"
|
24
|
+
|
25
|
+
Where
|
26
|
+
filename: filename(s) to scan.
|
27
|
+
shell command: shell command to execute when a file is changed
|
28
|
+
|
29
|
+
Examples
|
30
|
+
--------
|
31
|
+
|
32
|
+
Run the echo command when the file myfile is changed:
|
33
|
+
|
34
|
+
$ filewatcher "myfile" "echo 'myfile has changed'"
|
35
|
+
|
36
|
+
Run any javascript in the current directory when it is updated in Windows
|
37
|
+
Powershell:
|
38
|
+
|
39
|
+
> filewatcher *.js "node %FILENAME%"
|
40
|
+
|
41
|
+
In Linux/OSX:
|
42
|
+
|
43
|
+
$ filewatcher *.js 'node $FILENAME'
|
44
|
+
|
45
|
+
Place filenames or filenames in quotes to use ruby filename globbing instead
|
46
|
+
of shell filename globbing. This will make filewatcher look for files in
|
47
|
+
subdirectories too.
|
48
|
+
|
49
|
+
> filewatcher "*.js" "node %FILENAME%"
|
50
|
+
|
51
|
+
In Linux/OSX:
|
52
|
+
|
53
|
+
> filewatcher '*.js' 'node $FILENAME'
|
54
|
+
|
55
|
+
Try to run the updated file as a script when it is updated by using the
|
56
|
+
--exec/-e option. Works with files with file extensions that looks like a
|
57
|
+
python, ruby, perl, php, javascript or awk script.
|
58
|
+
|
59
|
+
$ filewatcher -e *.rb
|
60
|
+
|
61
|
+
Print a list of all files matching *.css first and then output the filename
|
62
|
+
when a file is beeing updated by using the --list/-l option:
|
63
|
+
|
64
|
+
$ filewatcher -l *.css 'echo file: $FILENAME'
|
65
|
+
|
66
|
+
Watch the "src" and "test" folders recursively, and run test when the
|
67
|
+
filesystem gets updated:
|
68
|
+
|
69
|
+
$ filewatcher "src test" "ruby test/test_suite.rb"
|
70
|
+
|
71
|
+
Available enviroment variables
|
72
|
+
------------------------------
|
73
|
+
|
74
|
+
The environment variable $FILENAME is available in the shell command argument.
|
75
|
+
On unix like systems the command has to be enclosed in single quotes. To run
|
76
|
+
node whenever a javascript file is updated:
|
77
|
+
|
78
|
+
$ filewatcher *.js 'node $FILENAME'
|
79
|
+
|
80
|
+
The environment variables $FILEPATH, $FILEDIR and $FSEVENT is also available.
|
81
|
+
|
82
|
+
Command line options
|
83
|
+
--------------------
|
84
|
+
|
85
|
+
--interval, -i <f>: Interval in seconds to scan filesystem. Defaults to 0.5 seconds.
|
86
|
+
--exec, -e: Execute file as a script when file is updated.
|
87
|
+
--recurse, -r <s>: Recurse into the directory, watching everything matching 'expression'
|
88
|
+
--include, -n <s>: Include files (default: *)
|
89
|
+
--exclude, -x <s>: Exclude file(s) matching (default: "")
|
90
|
+
--list, -l: Print name of files being watched
|
91
|
+
--version, -v: Print version and exit
|
92
|
+
--help, -h: Show this message
|
93
|
+
|
94
|
+
Ruby API
|
95
|
+
--------
|
96
|
+
|
97
|
+
Watch a list of files and directories:
|
98
|
+
|
99
|
+
require 'filewatcher'
|
100
|
+
|
101
|
+
FileWatcher.new(["lib/", "Rakefile"]).watch do |filename|
|
102
|
+
puts "Updated " + filename
|
103
|
+
end
|
104
|
+
|
105
|
+
To detect if a file is updated, added or deleted:
|
106
|
+
|
107
|
+
FileWatcher.new(["README.rdoc"]).watch() do |filename, event|
|
108
|
+
if(event == :changed)
|
109
|
+
puts "File updated: " + filename
|
110
|
+
end
|
111
|
+
if(event == :delete)
|
112
|
+
puts "File deleted: " + filename
|
113
|
+
end
|
114
|
+
if(event == :new)
|
115
|
+
puts "Added file: " + filename
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
To check for changes more often than the default once every second:
|
120
|
+
|
121
|
+
FileWatcher.new(["README.rdoc"]).watch(0.5) do |filename|
|
122
|
+
puts "Updated " + filename
|
123
|
+
end
|
124
|
+
|
125
|
+
Print the names of the files found before watching files and folders:
|
126
|
+
|
127
|
+
FileWatcher.new(["lib/"],true).watch do |filename|
|
128
|
+
puts "Updated " + filename
|
129
|
+
end
|
130
|
+
=> Watching files:
|
131
|
+
lib/filewatcher.rb
|
132
|
+
|
133
|
+
Use patterns to match filenames in current directory and subdirectories. The
|
134
|
+
pattern is not a regular expression; instead it follows rules similar to shell
|
135
|
+
filename globbing. See Ruby
|
136
|
+
[documentation](http://www.ruby-doc.org/core-2.1.1/File.html#method-c-fnmatch)
|
137
|
+
for syntax.
|
138
|
+
|
139
|
+
FileWatcher.new(["*.rb", "*.xml"]).watch do |filename|
|
140
|
+
puts "Updated " + filename
|
141
|
+
end
|
142
|
+
|
143
|
+
The filewatcher library is just a single file with 96 LOC (including comments)
|
144
|
+
with no dependencies.
|
145
|
+
|
146
|
+
TODO
|
147
|
+
----
|
148
|
+
|
149
|
+
Use thor in the command line utility.
|
150
|
+
The Ruby API is fairly well tested but the command line program has been
|
151
|
+
buggy.
|
152
|
+
|
153
|
+
Credits
|
154
|
+
-------
|
155
|
+
|
156
|
+
Code inspired by Tom Lieber's blogg posting: http://alltom.com/pages/detecting-file-changes-with-ruby
|
157
|
+
|
158
|
+
Find method by c00lrguy: http://snippets.dzone.com/posts/show/5457
|
159
|
+
|
160
|
+
Globbing by Kristoffer Roupé https://github.com/kitofr
|
161
|
+
|
162
|
+
Note on Patches/Pull Requests
|
163
|
+
-----------------------------
|
164
|
+
|
165
|
+
* Fork the project.
|
166
|
+
* Make your feature addition or bug fix.
|
167
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
168
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
169
|
+
* Send me a pull request. Bonus points for topic branches.
|
170
|
+
|
171
|
+
|
172
|
+
Copyright
|
173
|
+
---------
|
174
|
+
|
175
|
+
Copyright (c) 2011 - 2014 Thomas Flemming. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,46 +1,29 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
|
+
require 'rake/testtask'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
gem.name = "filewatcher"
|
8
|
-
gem.summary = %Q{Simple filewatcher.}
|
9
|
-
gem.description = %Q{Detect changes in filesystem.}
|
10
|
-
gem.email = "thomas.flemming@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/thomasfl/filewatcher"
|
12
|
-
gem.executables = ["filewatcher"]
|
13
|
-
gem.authors = ["Thomas Flemming"]
|
14
|
-
gem.add_dependency 'trollop', '~> 2.0'
|
15
|
-
gem.licenses = ["MIT"]
|
16
|
-
end
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
-
end
|
20
|
-
|
21
|
-
begin
|
22
|
-
require 'rcov/rcovtask'
|
23
|
-
Rcov::RcovTask.new do |test|
|
24
|
-
test.libs << 'test'
|
25
|
-
test.pattern = 'test/**/test_*.rb'
|
26
|
-
test.verbose = true
|
27
|
-
end
|
28
|
-
rescue LoadError
|
29
|
-
task :rcov do
|
30
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
31
|
-
end
|
5
|
+
task :default => :test
|
6
|
+
task :test do
|
7
|
+
sh "bacon -Ilib -Itest --automatic --quiet"
|
32
8
|
end
|
33
9
|
|
34
|
-
|
10
|
+
# begin
|
11
|
+
# require 'jeweler'
|
12
|
+
# Jeweler::Tasks.new do |gem|
|
13
|
+
# gem.name = "filewatcher"
|
14
|
+
# gem.summary = %Q{Simple filewatcher.}
|
15
|
+
# gem.description = %Q{Detect changes in filesystem.}
|
16
|
+
# gem.email = "thomas.flemming@gmail.com"
|
17
|
+
# gem.homepage = "http://github.com/thomasfl/filewatcher"
|
18
|
+
# gem.executables = ["filewatcher"]
|
19
|
+
# gem.authors = ["Thomas Flemming"]
|
20
|
+
# gem.add_dependency 'trollop', '~> 2.0'
|
21
|
+
# gem.licenses = ["MIT"]
|
22
|
+
# end
|
23
|
+
# rescue LoadError
|
24
|
+
# puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
25
|
+
# end
|
35
26
|
|
36
|
-
task :
|
37
|
-
|
38
|
-
require 'rdoc/task'
|
39
|
-
Rake::RDocTask.new do |rdoc|
|
40
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
27
|
+
# task :test => :check_dependencies
|
41
28
|
|
42
|
-
|
43
|
-
rdoc.title = "filewatcher #{version}"
|
44
|
-
rdoc.rdoc_files.include('README*')
|
45
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
-
end
|
29
|
+
# task :default => :test
|
data/lib/filewatcher.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
class FileWatcher
|
5
5
|
|
6
6
|
def self.VERSION
|
7
|
-
return
|
7
|
+
return '0.3.5'
|
8
8
|
end
|
9
9
|
|
10
10
|
def initialize(unexpanded_filenames, print_filelist=false)
|
@@ -12,9 +12,9 @@ class FileWatcher
|
|
12
12
|
@last_mtimes = { }
|
13
13
|
@filenames = expand_directories(@unexpanded_filenames)
|
14
14
|
|
15
|
-
puts
|
15
|
+
puts 'Watching:' if print_filelist
|
16
16
|
@filenames.each do |filename|
|
17
|
-
raise
|
17
|
+
raise 'File does not exist' unless File.exist?(filename)
|
18
18
|
@last_mtimes[filename] = File.stat(filename).mtime
|
19
19
|
puts filename if print_filelist
|
20
20
|
end
|
@@ -62,6 +62,7 @@ class FileWatcher
|
|
62
62
|
end
|
63
63
|
mtime = File.stat(filename).mtime
|
64
64
|
updated = @last_mtimes[filename] < mtime
|
65
|
+
|
65
66
|
@last_mtimes[filename] = mtime
|
66
67
|
if(updated)
|
67
68
|
@updated_file = filename
|
@@ -82,15 +83,15 @@ class FileWatcher
|
|
82
83
|
if(File.directory?(filename))
|
83
84
|
filenames = filenames + find(filename)
|
84
85
|
else
|
85
|
-
filenames = filenames + find(
|
86
|
+
filenames = filenames + find('.', filename, true)
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
89
90
|
return filenames.uniq
|
90
91
|
end
|
91
92
|
|
92
|
-
def find(dir, filename=
|
93
|
-
Dir[ subdirs ? File.join(dir.split(/\\/),
|
93
|
+
def find(dir, filename='*.*', subdirs=true)
|
94
|
+
Dir[ subdirs ? File.join(dir.split(/\\/), '**', filename) : File.join(dir.split(/\\/), filename) ]
|
94
95
|
end
|
95
96
|
|
96
97
|
end
|
data/test/fixtures/file1.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
content2
|
data/test/fixtures/file2.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
content
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bacon'
|
3
|
+
require 'fileutils'
|
4
|
+
require File.expand_path("../lib/filewatcher.rb",File.dirname(__FILE__))
|
5
|
+
|
6
|
+
describe FileWatcher do
|
7
|
+
|
8
|
+
it "should detect file deletions" do
|
9
|
+
filename = "test/fixtures/file1.txt"
|
10
|
+
open(filename,"w") { |f| f.puts "content1" }
|
11
|
+
filewatcher = FileWatcher.new(["test/fixtures"])
|
12
|
+
filewatcher.filesystem_updated?.should.be.false
|
13
|
+
FileUtils.rm(filename)
|
14
|
+
filewatcher.filesystem_updated?.should.be.true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should detect file additions" do
|
18
|
+
filename = "test/fixtures/file1.txt"
|
19
|
+
FileUtils.rm(filename) if File.exists?(filename)
|
20
|
+
filewatcher = FileWatcher.new(["test/fixtures"])
|
21
|
+
filewatcher.filesystem_updated?.should.be.false
|
22
|
+
open(filename,"w") { |f| f.puts "content1" }
|
23
|
+
filewatcher.filesystem_updated?.should.be.true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should detect file updates" do
|
27
|
+
filename = "test/fixtures/file1.txt"
|
28
|
+
open(filename,"w") { |f| f.puts "content1" }
|
29
|
+
filewatcher = FileWatcher.new(["test/fixtures"])
|
30
|
+
filewatcher.filesystem_updated?.should.be.false
|
31
|
+
sleep 1
|
32
|
+
open(filename,"w") { |f| f.puts "content2" }
|
33
|
+
filewatcher.filesystem_updated?.should.be.true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should detect new files in subfolders" do
|
37
|
+
subfolder = 'test/fixtures/new_sub_folder'
|
38
|
+
filewatcher = FileWatcher.new(["test/fixtures"])
|
39
|
+
filewatcher.filesystem_updated?.should.be.false
|
40
|
+
FileUtils::mkdir_p subfolder
|
41
|
+
filewatcher.filesystem_updated?.should.be.false
|
42
|
+
open(subfolder + "/file.txt","w") { |f| f.puts "xyz" }
|
43
|
+
filewatcher.filesystem_updated?.should.be.true
|
44
|
+
FileUtils.rm_rf subfolder
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filewatcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Flemming
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|
@@ -24,28 +24,54 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bacon
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
27
55
|
description: Detect changes in filesystem.
|
28
|
-
email:
|
56
|
+
email:
|
57
|
+
- thomas.flemming@gmail.com
|
29
58
|
executables:
|
30
59
|
- filewatcher
|
31
60
|
extensions: []
|
32
|
-
extra_rdoc_files:
|
33
|
-
- LICENSE
|
34
|
-
- README.rdoc
|
61
|
+
extra_rdoc_files: []
|
35
62
|
files:
|
36
63
|
- LICENSE
|
37
|
-
- README.
|
64
|
+
- README.md
|
38
65
|
- Rakefile
|
39
|
-
- VERSION
|
40
66
|
- bin/filewatcher
|
41
67
|
- lib/filewatcher.rb
|
42
|
-
- test/filewatcher_spec.rb
|
43
68
|
- test/fixtures/file1.txt
|
44
69
|
- test/fixtures/file2.txt
|
45
70
|
- test/fixtures/file3.rb
|
46
71
|
- test/fixtures/file4.rb
|
47
72
|
- test/fixtures/subdir/file5.rb
|
48
73
|
- test/fixtures/subdir/file6.rb
|
74
|
+
- test/test_filewatcher.rb
|
49
75
|
homepage: http://github.com/thomasfl/filewatcher
|
50
76
|
licenses:
|
51
77
|
- MIT
|
@@ -69,5 +95,12 @@ rubyforge_project:
|
|
69
95
|
rubygems_version: 2.2.2
|
70
96
|
signing_key:
|
71
97
|
specification_version: 4
|
72
|
-
summary:
|
73
|
-
test_files:
|
98
|
+
summary: Lighweight filewatcher.
|
99
|
+
test_files:
|
100
|
+
- test/fixtures/file1.txt
|
101
|
+
- test/fixtures/file2.txt
|
102
|
+
- test/fixtures/file3.rb
|
103
|
+
- test/fixtures/file4.rb
|
104
|
+
- test/fixtures/subdir/file5.rb
|
105
|
+
- test/fixtures/subdir/file6.rb
|
106
|
+
- test/test_filewatcher.rb
|
data/README.rdoc
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
= Filewatcher
|
2
|
-
|
3
|
-
Simple file watcher. Monitors changes in filesystem by polling. API has no dependencies.
|
4
|
-
|
5
|
-
= Install
|
6
|
-
|
7
|
-
Needs Ruby and Rubygems:
|
8
|
-
|
9
|
-
$ [sudo] gem install filewatcher
|
10
|
-
|
11
|
-
= Command line utility
|
12
|
-
|
13
|
-
Filewatcher scans filesystem and execute shell commands when files changes.
|
14
|
-
|
15
|
-
Usage:
|
16
|
-
filewatcher [-i interval] "<filename>" "<shell command>"
|
17
|
-
Where
|
18
|
-
filename: filename(s) to scan.
|
19
|
-
shell command: shell command to execute when file changes on disk.
|
20
|
-
|
21
|
-
= Examples
|
22
|
-
|
23
|
-
Run the echo command when the file myfile is changed:
|
24
|
-
|
25
|
-
$ filewatcher "myfile" "echo 'myfile has changed'"
|
26
|
-
|
27
|
-
Run any javascript in the current directory when it is updated in Windows Powershell:
|
28
|
-
|
29
|
-
> filewatcher *.js "node %FILENAME%"
|
30
|
-
|
31
|
-
In Linux/OSX:
|
32
|
-
|
33
|
-
$ filewatcher *.js 'node $FILENAME'
|
34
|
-
|
35
|
-
Place filenames or filenames in quotes to use ruby filename globbing instead of shell filename globbing. This will make filewatcher look for files in subdirectories too.
|
36
|
-
|
37
|
-
> filewatcher "*.js" "node %FILENAME%"
|
38
|
-
|
39
|
-
In Linux/OSX:
|
40
|
-
|
41
|
-
> filewatcher '*.js' 'node $FILENAME'
|
42
|
-
|
43
|
-
Try to run the updated file as a script when it is updated by using the --exec/-e option. Works with files with file extensions that looks like a python, ruby, perl, php,
|
44
|
-
javascript or awk script.
|
45
|
-
|
46
|
-
$ filewatcher -e *.rb
|
47
|
-
|
48
|
-
Print a list of all files matching *.css first and then output the filename when a file is beeing updated by using the --list/-l option:
|
49
|
-
|
50
|
-
$ filewatcher -l *.css 'echo file: $FILENAME'
|
51
|
-
|
52
|
-
Watch the "src" and "test" folders recursively, and run test when the filesystem gets updated:
|
53
|
-
|
54
|
-
$ filewatcher "src test" "ruby test/test_suite.rb"
|
55
|
-
|
56
|
-
= Available enviroment variables
|
57
|
-
|
58
|
-
The environment variable $FILENAME is available in the command. On unix like systems the command
|
59
|
-
has to be enclosed in single quotes. To run node whenever a javascript file is updated:
|
60
|
-
|
61
|
-
$ filewatcher *.js 'node $FILENAME'
|
62
|
-
|
63
|
-
The environment variables $FILEPATH, $FILEDIR and $FSEVENT is also available.
|
64
|
-
|
65
|
-
= Command line options
|
66
|
-
|
67
|
-
--interval, -i <f>: Interval in seconds to scan filesystem. Defaults to 0.5 seconds.
|
68
|
-
--exec, -e: Execute file as a script when file is updated.
|
69
|
-
--recurse, -r <s>: Recurse into the directory, watching everything matching 'expression'
|
70
|
-
--include, -n <s>: Include files (default: *)
|
71
|
-
--exclude, -x <s>: Exclude file(s) matching (default: "")
|
72
|
-
--list, -l: Print name of files being watched
|
73
|
-
--version, -v: Print version and exit
|
74
|
-
--help, -h: Show this message
|
75
|
-
|
76
|
-
= Ruby API
|
77
|
-
|
78
|
-
Examples:
|
79
|
-
|
80
|
-
Watch a list of files and directories:
|
81
|
-
|
82
|
-
require 'filewatcher'
|
83
|
-
|
84
|
-
FileWatcher.new(["lib/", "Rakefile"]).watch do |filename|
|
85
|
-
puts "Updated " + filename
|
86
|
-
end
|
87
|
-
|
88
|
-
To detect if a file is updated, added or deleted:
|
89
|
-
|
90
|
-
FileWatcher.new(["README.rdoc"]).watch() do |filename, event|
|
91
|
-
if(event == :changed)
|
92
|
-
puts "File updated: " + filename
|
93
|
-
end
|
94
|
-
if(event == :delete)
|
95
|
-
puts "File deleted: " + filename
|
96
|
-
end
|
97
|
-
if(event == :new)
|
98
|
-
puts "Added file: " + filename
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
To check for changes more often than the default once every second:
|
103
|
-
|
104
|
-
FileWatcher.new(["README.rdoc"]).watch(0.5) do |filename|
|
105
|
-
puts "Updated " + filename
|
106
|
-
end
|
107
|
-
|
108
|
-
Print the names of the files found before watching files and folders:
|
109
|
-
|
110
|
-
FileWatcher.new(["lib/"],true).watch do |filename|
|
111
|
-
puts "Updated " + filename
|
112
|
-
end
|
113
|
-
=> Watching files:
|
114
|
-
lib/filewatcher.rb
|
115
|
-
|
116
|
-
Use patterns to match filenames in current directory and subdirectories. The pattern is not a regular expression; instead it follows rules similar to shell filename globbing. Se Ruby documentation[http://www.ruby-doc.org/core-2.1.1/File.html#method-c-fnmatch] for syntax.
|
117
|
-
|
118
|
-
FileWatcher.new(["*.rb", "*.xml"]).watch do |filename|
|
119
|
-
puts "Updated " + filename
|
120
|
-
end
|
121
|
-
|
122
|
-
= TODO
|
123
|
-
|
124
|
-
The Ruby API is fairly well tested but the command line program is buggy at the time beeing.
|
125
|
-
|
126
|
-
= Credits
|
127
|
-
|
128
|
-
Code inspired by Tom Lieber's blogg posting: http://alltom.com/pages/detecting-file-changes-with-ruby
|
129
|
-
|
130
|
-
Find method by c00lrguy: http://snippets.dzone.com/posts/show/5457
|
131
|
-
|
132
|
-
Globbing by Kristoffer Roupé https://github.com/kitofr
|
133
|
-
|
134
|
-
== Note on Patches/Pull Requests
|
135
|
-
|
136
|
-
* Fork the project.
|
137
|
-
* Make your feature addition or bug fix.
|
138
|
-
* Add tests for it. This is important so I don't break it in a
|
139
|
-
future version unintentionally.
|
140
|
-
* Commit, do not mess with rakefile, version, or history.
|
141
|
-
(if you want to have your own version, that is fine but
|
142
|
-
bump version in a commit by itself I can ignore when I pull)
|
143
|
-
* Send me a pull request. Bonus points for topic branches.
|
144
|
-
|
145
|
-
== Copyright
|
146
|
-
|
147
|
-
Copyright (c) 2011 - 2014 Thomas Flemming. See LICENSE for details.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.3.4
|
data/test/filewatcher_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'minitest/autorun'
|
3
|
-
require_relative '../lib/filewatcher'
|
4
|
-
|
5
|
-
describe FileWatcher do
|
6
|
-
|
7
|
-
filewatcher = FileWatcher.new([])
|
8
|
-
|
9
|
-
it "can find single files" do
|
10
|
-
files = filewatcher.expand_directories(["fixtures/file1.txt"])
|
11
|
-
assert files.size == 1
|
12
|
-
end
|
13
|
-
|
14
|
-
it "can expand directories recursively" do
|
15
|
-
files = filewatcher.expand_directories(["fixtures/"])
|
16
|
-
assert files.size == 6
|
17
|
-
files = filewatcher.expand_directories(["fixtures"])
|
18
|
-
assert files.size == 6
|
19
|
-
files = filewatcher.expand_directories(["./fixtures"])
|
20
|
-
assert files.size == 6
|
21
|
-
end
|
22
|
-
|
23
|
-
it "can use filename globbing to filter names" do
|
24
|
-
files = filewatcher.expand_directories(["fixtures/*.rb"])
|
25
|
-
assert files.size == 2
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|