filewatcher 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ce65dd1aeaf7054fd9a91b6787778569bccf8a8
4
- data.tar.gz: 55cd4d125598d649b22f44c7225183c7163bf3f5
3
+ metadata.gz: 24a9b40e9d109eadc83d2299a577b701c376a5c8
4
+ data.tar.gz: 159e4cf47ace11192f7ccae447008d2af2343a6a
5
5
  SHA512:
6
- metadata.gz: 4c8b05df1ad574ce4a7c47d2b462c052d6c5e722b01f9b2da86c030af313170a2fd650988f2849ef32ad53e07c1217ac7ca72ed3b1b4b0c78a94af2357beb800
7
- data.tar.gz: ad255b8e5655655f974dcd2e43623c9b0eefb660c6f5c99c50c174f8425eb6d4f6e80b477e0b954bbfb1a349dd7be013613caad4f3e90698610b4d84cacf4a82
6
+ metadata.gz: badd71331331d31b5e2bcd5db3654794332fa629fac3cdf46ae82db47d31f790e8e3952411b347816952433c8aa56864d64154ee1eac1c76feb3a302e27e7844
7
+ data.tar.gz: fcd7f82251d8dcc1625f9e8e74b5e9c171e3b1d0da493ad5551f3c36f9154fbb98c33f341cdf1656cf2d3c0bac44877bfde2ecc44401768ee1e75c1db32b57a5
@@ -24,25 +24,35 @@ Run the echo command when the file myfile is changed:
24
24
 
25
25
  $ filewatcher "myfile" "echo 'myfile has changed'"
26
26
 
27
- Run any javascript in the current folder when it is updated in Windows Powershell:
27
+ Run any javascript in the current directory when it is updated in Windows Powershell:
28
28
 
29
29
  > filewatcher *.js "node %FILENAME%"
30
30
 
31
31
  In Linux/OSX:
32
32
 
33
- $ filewatcher *.js "node $FILENAME"
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%"
34
38
 
39
+ In Linux/OSX:
35
40
 
36
- Run the ruby script when it is changed:
41
+ > filewatcher '*.js' 'node $FILENAME'
37
42
 
38
- $ filewatcher -e ruby-script.rb
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.
39
45
 
40
- Works with ruby, perl, python and awk by detecting file extensions.
46
+ $ filewatcher -e *.rb
41
47
 
42
- Print a list of all files matching *.css first and the print filename when a file is beeing updated:
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:
43
49
 
44
50
  $ filewatcher -l *.css 'echo file: $FILENAME'
45
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
+
46
56
  = Available enviroment variables
47
57
 
48
58
  The environment variable $FILENAME is available in the command. On unix like systems the command
@@ -50,7 +60,7 @@ has to be enclosed in single quotes. To run node whenever a javascript file is u
50
60
 
51
61
  $ filewatcher *.js 'node $FILENAME'
52
62
 
53
- The environment variables $FILEPATH and $FILEDIR is also available.
63
+ The environment variables $FILEPATH, $FILEDIR and $FSEVENT is also available.
54
64
 
55
65
  = Command line options
56
66
 
@@ -75,7 +85,7 @@ Watch a list of files and directories:
75
85
  puts "Updated " + filename
76
86
  end
77
87
 
78
- To detect if a file is updated or deleted:
88
+ To detect if a file is updated, added or deleted:
79
89
 
80
90
  FileWatcher.new(["README.rdoc"]).watch() do |filename, event|
81
91
  if(event == :changed)
@@ -85,7 +95,7 @@ To detect if a file is updated or deleted:
85
95
  puts "File deleted: " + filename
86
96
  end
87
97
  if(event == :new)
88
- puts "New file: " + filename
98
+ puts "Added file: " + filename
89
99
  end
90
100
  end
91
101
 
@@ -95,7 +105,7 @@ To check for changes more often than the default once every second:
95
105
  puts "Updated " + filename
96
106
  end
97
107
 
98
- Print the names of files beeing watched before we begin:
108
+ Print the names of the files found before watching files and folders:
99
109
 
100
110
  FileWatcher.new(["lib/"],true).watch do |filename|
101
111
  puts "Updated " + filename
@@ -103,7 +113,7 @@ Print the names of files beeing watched before we begin:
103
113
  => Watching files:
104
114
  lib/filewatcher.rb
105
115
 
106
- Use patterns to match filenames. 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.
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.
107
117
 
108
118
  FileWatcher.new(["*.rb", "*.xml"]).watch do |filename|
109
119
  puts "Updated " + filename
data/Rakefile CHANGED
@@ -11,7 +11,6 @@ begin
11
11
  gem.homepage = "http://github.com/thomasfl/filewatcher"
12
12
  gem.executables = ["filewatcher"]
13
13
  gem.authors = ["Thomas Flemming"]
14
- # gem.add_dependency "trollop", ">= 1.16.2"
15
14
  gem.add_dependency 'trollop', '~> 2.0'
16
15
  gem.licenses = ["MIT"]
17
16
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -17,7 +17,7 @@ Where
17
17
 
18
18
  Examples:
19
19
  filewatcher "myfile" "echo 'myfile has changed'"
20
- filewatcher -i 2 "*.rb ../src/*.rb" "ruby run_tests.rb"
20
+ filewatcher '*.rb' 'ruby $FILENAME'
21
21
 
22
22
  Options:
23
23
  EOS
@@ -48,19 +48,53 @@ if(options[:recurse])
48
48
  files = inc - exc
49
49
  end
50
50
 
51
- runners = {".py" => "python", ".rb" => "ruby", ".pl" => "perl", ".awk" => "awk"}
51
+ def split_files_void_escaped_whitespace(files)
52
+ splitted_filenames = []
53
+ files.each do |name|
54
+ name = name.gsub(/\\\s/,'_ESCAPED_WHITESPACE_')
55
+ splitted_filenames << name.split(/\s/)
56
+ end
57
+ files = splitted_filenames.flatten.uniq
58
+ splitted_filenames = []
59
+ files.each do |name|
60
+ splitted_filenames << name.gsub('_ESCAPED_WHITESPACE_','\ ')
61
+ end
62
+ files = splitted_filenames
63
+ end
64
+
65
+ files = split_files_void_escaped_whitespace(files)
52
66
 
53
67
  FileWatcher.new(files, options[:list]).watch(options[:interval]) do |filename, event|
54
- if(options[:exec])
55
- extension = filename[/(\.[^\.]*)/,0]
56
- runner = runners[extension].to_s
57
- system(runner + " " + filename)
58
- elsif(ARGV[-1])then
59
- path = Pathname.new(filename)
68
+ cmd = nil
69
+ if(options[:exec] and File.exist?(filename))
70
+ extension = filename[/(\.[^\.]*)$/,0]
71
+ runners = {
72
+ ".py" => "python",
73
+ ".js" => "node",
74
+ ".rb" => "ruby",
75
+ ".pl" => "perl",
76
+ ".awk" => "awk",
77
+ ".php" => "php",
78
+ ".phtml" => "php",
79
+ ".php4" => "php",
80
+ ".php3" => "php",
81
+ ".php5" => "php",
82
+ ".phps" => "php"
83
+ }
84
+ runner = runners[extension]
85
+ if(runner)
86
+ cmd = "env #{runner.to_s} #{filename}"
87
+ end
88
+ elsif(ARGV.length > 1)
60
89
  cmd = ARGV[-1]
90
+ end
91
+
92
+ if(cmd)
93
+ path = Pathname.new(filename)
61
94
  env = {
62
95
  'FILENAME'=> path.to_s,
63
- 'FILEDIR' => path.parent.realpath.to_s
96
+ 'FILEDIR' => path.parent.realpath.to_s,
97
+ 'FSEVENT' => event.to_s
64
98
  }
65
99
  if(event != :delete)
66
100
  ENV['FILEPATH'] = path.realpath.to_s
@@ -80,4 +114,5 @@ FileWatcher.new(files, options[:list]).watch(options[:interval]) do |filename, e
80
114
  end
81
115
  puts ": " + filename
82
116
  end
117
+
83
118
  end
@@ -4,7 +4,7 @@
4
4
  class FileWatcher
5
5
 
6
6
  def self.VERSION
7
- return "0.3.3"
7
+ return "0.3.4"
8
8
  end
9
9
 
10
10
  def initialize(unexpanded_filenames, print_filelist=false)
@@ -0,0 +1,28 @@
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
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ puts "Hello world from Ruby!!!"
@@ -0,0 +1 @@
1
+ puts "This is file6.rb executing"
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.3
4
+ version: 0.3.4
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-04-11 00:00:00.000000000 Z
11
+ date: 2014-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop
@@ -39,6 +39,13 @@ files:
39
39
  - VERSION
40
40
  - bin/filewatcher
41
41
  - lib/filewatcher.rb
42
+ - test/filewatcher_spec.rb
43
+ - test/fixtures/file1.txt
44
+ - test/fixtures/file2.txt
45
+ - test/fixtures/file3.rb
46
+ - test/fixtures/file4.rb
47
+ - test/fixtures/subdir/file5.rb
48
+ - test/fixtures/subdir/file6.rb
42
49
  homepage: http://github.com/thomasfl/filewatcher
43
50
  licenses:
44
51
  - MIT