filewatcher 0.1.5 → 0.1.8

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.
@@ -1,6 +1,6 @@
1
1
  = Filewatcher
2
2
 
3
- Simple file watcher. Monitors changes in files by polling files.
3
+ Simple file watcher. Monitors changes in files by polling.
4
4
 
5
5
  = Command line utility
6
6
 
@@ -12,16 +12,47 @@ Where
12
12
  filename: filename(s) to scan.
13
13
  shell command: shell command to execute when file changes on disk.
14
14
 
15
- Examples:
16
- filewatcher "myfile" "echo 'myfile has changed'"
17
- filewathcer -i 2 "*.rb ../src/*.rb" "ruby run_tests.rb"
15
+ = Examples:
16
+
17
+ Run the echo command when the file myfile is changed:
18
+
19
+ $ filewatcher "myfile" "echo 'myfile has changed'"
20
+
21
+ Run the ruby script when it is changed:
22
+
23
+ $ filewatcher -e ruby-script.rb
24
+
25
+ Works with ruby, perl, python and awk by detecting file extensions.
26
+
27
+ At 2 seconds intervall check all files matching *.rb and ../src/*.rb, and run "ruby run_tests.rb".
28
+
29
+ $ filewatcher -i 2 "*.rb ../src/*.rb" "ruby run_tests.rb"
30
+
31
+ = Globbing
32
+
33
+ Print a list of all files matching *.css at start and the:
34
+
35
+ $ filewatcher -l *.css
36
+
37
+ = Available enviroment variables
38
+
39
+ The environment variable $FILENAME is available in the command. On unix like systems the command
40
+ has to be enclosed in single quotes. To run node whenever a javascript file is update:
41
+
42
+ $ filewatcher *.js 'node $FILENAME'
43
+
44
+ The environment variables $FILEPATH and $FILEDIR is also available.
18
45
 
19
46
  Options:
20
- --interval, -i <f>: Interval to scan filesystem. Defaults to 0.5 seconds.
47
+ --interval, -i <f>: Interval to scan filesystem. Defaults to 0.5 seconds. (Default: 0.5)
48
+ --exec, -e: Execute file as a script when file is updated.
49
+ --recurse, -r <s>: Recurse into the directory, watching everything matching 'expression'
50
+ --include, -n <s>: Include files (default: *)
51
+ --exclude, -x <s>: Exclude file(s) matching (default: "")
52
+ --list, -l: Print name of files being watched
21
53
  --version, -v: Print version and exit
22
54
  --help, -h: Show this message
23
55
 
24
-
25
56
  = Install
26
57
 
27
58
  sudo gem install filewatcher
@@ -54,6 +85,9 @@ To check for changes more often than once every second:
54
85
  puts "Updated " + filename
55
86
  end
56
87
 
88
+ = TODO
89
+
90
+ The Ruby API is fairly well tested but the command line program is buggy at the time beeing.
57
91
 
58
92
  = Credits
59
93
 
@@ -61,6 +95,8 @@ Code inspired by Tom Lieber's blogg posting: http://alltom.com/pages/detecting-f
61
95
 
62
96
  Find method by c00lrguy: http://snippets.dzone.com/posts/show/5457
63
97
 
98
+ Globbing by Kristoffer Roupé https://github.com/kitofr
99
+
64
100
  == Note on Patches/Pull Requests
65
101
 
66
102
  * Fork the project.
@@ -74,4 +110,4 @@ Find method by c00lrguy: http://snippets.dzone.com/posts/show/5457
74
110
 
75
111
  == Copyright
76
112
 
77
- Copyright (c) 2011 Thomas Flemming. See LICENSE for details.
113
+ Copyright (c) 2011 - 2013 Thomas Flemming. See LICENSE for details.
data/Rakefile CHANGED
@@ -43,7 +43,7 @@ task :test => :check_dependencies
43
43
 
44
44
  task :default => :test
45
45
 
46
- require 'rake/rdoctask'
46
+ require 'rdoc/task'
47
47
  Rake::RDocTask.new do |rdoc|
48
48
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
49
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.8
@@ -2,9 +2,10 @@
2
2
  require 'rubygems'
3
3
  require 'filewatcher'
4
4
  require 'trollop'
5
+ require 'pathname'
5
6
 
6
7
  options = Trollop::options do
7
- version "filewatcher, version 0.1.4 by Thomas Flemming 2011"
8
+ version "filewatcher, version 0.1.8 by Thomas Flemming 2011"
8
9
  banner <<-EOS
9
10
  Filewatcher scans filesystem and execute shell commands when files changes.
10
11
 
@@ -16,33 +17,54 @@ Where
16
17
 
17
18
  Examples:
18
19
  filewatcher "myfile" "echo 'myfile has changed'"
19
- filewathcer -i 2 "*.rb ../src/*.rb" "ruby run_tests.rb"
20
+ filewatcher -i 2 "*.rb ../src/*.rb" "ruby run_tests.rb"
20
21
 
21
22
  Options:
22
23
  EOS
23
24
 
24
25
  opt :interval, "Interval to scan filesystem. Defaults to 0.5 seconds.", :short => 'i', :type => :float, :default => 0.5
25
- opt :run, "Run file as a program when file is updated.", :short => 'r', :type => :boolean, :default => false
26
+ opt :exec, "Execute file as a script when file is updated.", :short => 'e', :type => :boolean, :default => false
27
+ opt :recurse, "Recurse into the directory, watching everything matching 'expression'", :short => 'r', :type => :string
28
+ opt :include, "Include files", :type => :string, :default => "*"
29
+ opt :exclude, "Exclude file(s) matching", :type => :string, :default => ""
30
+ opt :list, "Print name of files being watched"
26
31
  end
27
32
 
28
- Trollop::die "must have one or two arguments" if(ARGV.size == 0 or ARGV.size > 2)
33
+ Trollop::die "must have at least one argument" if(ARGV.size == 0)
29
34
 
30
35
  files = []
31
- ARGV[0].split(/\s+/).each do |arg|
32
- Dir.glob(arg).each do |file|
33
- files << file
34
- end
36
+ ARGV[0...-1].each do |a|
37
+ files << a
38
+ end
39
+
40
+ if(ARGV.length == 1)
41
+ files << ARGV[0]
42
+ end
43
+
44
+ if(options[:recurse])
45
+ base = File.join(options[:recurse], "**")
46
+ inc = Dir.glob(File.join(base, options[:include]))
47
+ exc = Dir.glob(File.join(base, options[:exclude]))
48
+ files = inc - exc
49
+ end
50
+
51
+ if(options[:list])
52
+ puts "watching:", files.inspect
35
53
  end
36
54
 
37
55
  runners = {".py" => "python", ".rb" => "ruby", ".pl" => "perl", ".awk" => "awk"}
38
56
 
39
57
  FileWatcher.new(files).watch(options[:interval]) do |filename|
40
- if(options[:run])
58
+ if(options[:exec])
41
59
  extension = filename[/(\.[^\.]*)/,0]
42
60
  runner = runners[extension].to_s
43
61
  system(runner + " " + filename)
44
- elsif(ARGV[1])then
45
- system(ARGV[1])
62
+ elsif(ARGV[-1])then
63
+ path = Pathname.new(filename)
64
+ ENV['FILENAME'] = path.to_s
65
+ ENV['FILEPATH'] = path.realpath.to_s
66
+ ENV['FILEDIR'] = path.parent.realpath.to_s
67
+ system(ARGV[-1])
46
68
  else
47
69
  puts "file updated: " + filename
48
70
  end
@@ -1,3 +1,4 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '.'))
1
2
  require 'helper'
2
3
 
3
4
  class TestFilewatcher < Test::Unit::TestCase
@@ -14,7 +15,6 @@ class TestFilewatcher < Test::Unit::TestCase
14
15
 
15
16
  end
16
17
 
17
-
18
18
  # should "should detect changes in files" do
19
19
 
20
20
  # @pid = fork do
@@ -36,4 +36,3 @@ class TestFilewatcher < Test::Unit::TestCase
36
36
  # end
37
37
 
38
38
  end
39
-
metadata CHANGED
@@ -1,58 +1,47 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: filewatcher
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 5
9
- version: 0.1.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.8
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Thomas Flemming
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-06-24 00:00:00 +02:00
18
- default_executable: filewatcher
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: thoughtbot-shoulda
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
16
+ requirement: &70212885464580 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
30
22
  type: :development
31
- version_requirements: *id001
32
- - !ruby/object:Gem::Dependency
33
- name: trollop
34
23
  prerelease: false
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- segments:
40
- - 1
41
- - 16
42
- - 2
24
+ version_requirements: *70212885464580
25
+ - !ruby/object:Gem::Dependency
26
+ name: trollop
27
+ requirement: &70212885464060 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
43
32
  version: 1.16.2
44
33
  type: :runtime
45
- version_requirements: *id002
34
+ prerelease: false
35
+ version_requirements: *70212885464060
46
36
  description: Detect changes in files.
47
37
  email: thomas.flemming@gmail.com
48
- executables:
38
+ executables:
49
39
  - filewatcher
50
40
  extensions: []
51
-
52
- extra_rdoc_files:
41
+ extra_rdoc_files:
53
42
  - LICENSE
54
43
  - README.rdoc
55
- files:
44
+ files:
56
45
  - LICENSE
57
46
  - README.rdoc
58
47
  - Rakefile
@@ -61,35 +50,28 @@ files:
61
50
  - lib/filewatcher.rb
62
51
  - test/helper.rb
63
52
  - test/test_filewatcher.rb
64
- has_rdoc: true
65
53
  homepage: http://github.com/thomasfl/filewatcher
66
54
  licenses: []
67
-
68
55
  post_install_message:
69
56
  rdoc_options: []
70
-
71
- require_paths:
57
+ require_paths:
72
58
  - lib
73
- required_ruby_version: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- segments:
78
- - 0
79
- version: "0"
80
- required_rubygems_version: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- segments:
85
- - 0
86
- version: "0"
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
87
71
  requirements: []
88
-
89
72
  rubyforge_project:
90
- rubygems_version: 1.3.6
73
+ rubygems_version: 1.8.11
91
74
  signing_key:
92
75
  specification_version: 3
93
76
  summary: Simple filewatcher.
94
77
  test_files: []
95
-