guard 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2011 Thibaud Guillaume-Gentil
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
1
+ Copyright (c) 2011 Thibaud Guillaume-Gentil
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
20
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,431 +1,464 @@
1
- Guard [![Build Status](https://secure.travis-ci.org/guard/guard.png)](http://travis-ci.org/guard/guard)
2
- =====
3
-
4
- Guard is a command line tool that easily handle events on files modifications.
5
-
6
- If you have any questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard` (irc.freenode.net).
7
-
8
- Features
9
- --------
10
-
11
- * [FSEvent](http://en.wikipedia.org/wiki/FSEvents) support on Mac OS X 10.5+ (without RubyCocoa!, [rb-fsevent gem, >= 0.3.5](https://rubygems.org/gems/rb-fsevent) required).
12
- * [Inotify](http://en.wikipedia.org/wiki/Inotify) support on Linux ([rb-inotify gem, >= 0.5.1](https://rubygems.org/gems/rb-inotify) required).
13
- * [Directory Change Notification](http://msdn.microsoft.com/en-us/library/aa365261\(VS.85\).aspx) support on Windows ([rb-fchange, >= 0.0.2](https://rubygems.org/gems/rb-fchange) required).
14
- * Polling on the other operating systems (help us to support more OS).
15
- * Automatic & Super fast (when polling is not used) files modifications detection (even new files are detected).
16
- * Visual notifications on Mac OSX ([Growl](http://growl.info)), Linux ([Libnotify](http://developer.gnome.org/libnotify)) and Windows ([Notifu](http://www.paralint.com/projects/notifu)).
17
- * Tested against Ruby 1.8.7, 1.9.2, REE and the latest versions of JRuby & Rubinius.
18
-
19
- Screencast
20
- ----------
21
-
22
- Ryan Bates made a Railscast on Guard, you can view it here: http://railscasts.com/episodes/264-guard
23
-
24
- Install
25
- -------
26
-
27
- Install the gem:
28
-
29
- $ gem install guard
30
-
31
- Or add it to your Gemfile (inside the `development` group):
32
-
33
- gem 'guard'
34
-
35
- and install it via Bundler:
36
-
37
- $ bundle install
38
-
39
- Generate an empty Guardfile with:
40
-
41
- $ guard init
42
-
43
- You may optionally place a .Guardfile in your home directory to use it across multiple projects.
44
- Also note that if a `.guard.rb` is found in your home directory, it will be appended to the Guardfile.
45
-
46
- Add the guards you need to your Guardfile (see the existing guards below).
47
-
48
- ### On Mac OS X
49
-
50
- Install the rb-fsevent gem for [FSEvent](http://en.wikipedia.org/wiki/FSEvents) support:
51
-
52
- $ gem install rb-fsevent
53
-
54
- You have two possibilities:
55
-
56
- Use the [growl_notify gem](https://rubygems.org/gems/growl_notify) (recommended):
57
-
58
- $ gem install growl_notify
59
-
60
- Use the [growlnotify](http://growl.info/extras.php#growlnotify) (cli tool for growl) + the [growl gem](https://rubygems.org/gems/growl).
61
-
62
- $ brew install growlnotify
63
- $ gem install growl
64
-
65
- And add them to your Gemfile:
66
-
67
- gem 'rb-fsevent'
68
- gem 'growl_notify' # or gem 'growl'
69
-
70
- The difference between growl and growl_notify is that growl_notify uses AppleScript to
71
- display a message, whereas growl uses the `growlnotify` command. In general the AppleScript
72
- approach is preferred, but you may also use the older growl gem. Have a look at the
73
- [Guard Wiki](https://github.com/guard/guard/wiki/Use-growl_notify-or-growl-gem) for more information.
74
-
75
- ### On Linux
76
-
77
- Install the [rb-inotify gem](https://rubygems.org/gems/rb-inotify) for [inotify](http://en.wikipedia.org/wiki/Inotify) support:
78
-
79
- $ gem install rb-inotify
80
-
81
- Install the [libnotify gem](https://rubygems.org/gems/libnotify) if you want visual notification support:
82
-
83
- $ gem install libnotify
84
-
85
- And add them to your Gemfile:
86
-
87
- gem 'rb-inotify'
88
- gem 'libnotify'
89
-
90
- ### On Windows
91
-
92
- Install the [rb-fchange gem](https://rubygems.org/gems/rb-fchange) for [Directory Change Notification](http://msdn.microsoft.com/en-us/library/aa365261\(VS.85\).aspx) support:
93
-
94
- $ gem install rb-fchange
95
-
96
- Install the [win32console gem](https://rubygems.org/gems/win32console) if you want colors in your terminal:
97
-
98
- $ gem install win32console
99
-
100
- Install the [rb-notifu gem](https://rubygems.org/gems/rb-notifu) if you want visual notification support:
101
-
102
- $ gem install rb-notifu
103
-
104
- And add them to your Gemfile:
105
-
106
- gem 'rb-fchange'
107
- gem 'rb-notifu'
108
- gem 'win32console'
109
-
110
- Usage
111
- -----
112
-
113
- Just launch Guard inside your Ruby / Rails project with:
114
-
115
- $ guard [start]
116
-
117
- or if you use Bundler, to run the Guard executable specific to your bundle:
118
-
119
- $ bundle exec guard [start]
120
-
121
- Guard will look for a Guardfile in your current directory. If it does not find one, it will look in your `$HOME` directory for a .Guardfile.
122
-
123
- Command line options
124
- --------------------
125
-
126
- ### `-c`/`--clear` option
127
-
128
- Shell can be cleared after each change:
129
-
130
- $ guard --clear
131
- $ guard -c # shortcut
132
-
133
- ### `-n`/`--notify` option
134
-
135
- Notifications (growl/libnotify) can be disabled:
136
-
137
- $ guard --notify false
138
- $ guard -n f # shortcut
139
-
140
- Notifications can also be disabled globally by setting a `GUARD_NOTIFY` environment variable to `false`
141
-
142
- ### `-g`/`--group` option
143
-
144
- Only certain guards groups can be run (see the Guardfile DSL below for creating groups):
145
-
146
- $ guard --group group_name another_group_name
147
- $ guard -g group_name another_group_name # shortcut
148
-
149
- ### `-d`/`--debug` option
150
-
151
- Guard can be run in debug mode:
152
-
153
- $ guard --debug
154
- $ guard -d # shortcut
155
-
156
- ### `-w`/`--watchdir` option
157
-
158
- Guard can watch in any directory (instead of the current directory):
159
-
160
- $ guard --watchdir ~/your/fancy/project
161
- $ guard -w ~/your/fancy/project # shortcut
162
-
163
- ### `-G`/`--guardfile` option
164
-
165
- Guard can use a Guardfile not located in the current directory:
166
-
167
- $ guard --guardfile ~/.your_global_guardfile
168
- $ guard -G ~/.your_global_guardfile # shortcut
169
-
170
- ### `-A`/`--watch-all-modifications` option
171
-
172
- Guard can optionally watch all file modifications like moves or deletions with:
173
-
174
- ``` bash
175
- $ guard start -A
176
- $ guard start --watch-all-modifications
177
- ```
178
-
179
- An exhaustive list of options is available with:
180
-
181
- $ guard help [TASK]
182
-
183
- Interactions
184
- ------------
185
-
186
- **From version >= 0.7.0 Posix Signal handlers are no more used to interact with Guard. If you're using a version < 0.7, please refer to the [README in the v0.6 branch](https://github.com/guard/guard/blob/v0.6/README.md).**
187
-
188
- When Guard do nothing you can interact with by entering a command + hitting enter:
189
-
190
- * `stop|quit|exit|s|q|e + enter` - Calls each guard's `#stop` method, in the same order they are declared in the Guardfile, and then quits Guard itself.
191
- * `reload|r|z + enter` - Calls each guard's `#reload` method, in the same order they are declared in the Guardfile.
192
- * `pause|p + enter` - Toggle files modification listening. Useful when switching git branches.
193
- * `just enter (no commands)` - Calls each guard's `#run_all` method, in the same order they are declared in the Guardfile.
194
-
195
- Available Guards
196
- ----------------
197
-
198
- A list of the available guards is present [in the wiki](https://github.com/guard/guard/wiki/List-of-available-Guards).
199
-
200
- ### Add a guard to your Guardfile
201
-
202
- Add it to your Gemfile (inside the `development` group):
203
-
204
- gem '<guard-name>'
205
-
206
- You can list all guards installed on your system with:
207
-
208
- $ guard list
209
-
210
- Insert default guard's definition to your Guardfile by running this command:
211
-
212
- $ guard init <guard-name>
213
-
214
- You are good to go, or you can modify your guards' definition to suit your needs.
215
-
216
- Guardfile DSL
217
- -------------
218
-
219
- The Guardfile DSL consists of the following methods:
220
-
221
- * `#guard`: allows you to add a guard with an optional hash of options.
222
- * `#watch`: allows you to define which files are supervised by this guard. An optional block can be added to overwrite the paths sent to the guard's `#run_on_change` method or to launch any arbitrary command.
223
- * `#group`: allows you to group several guards together. Groups to be run can be specified with the Guard DSL option `--group` (or `-g`). This comes in handy especially when you have a huge Guardfile and want to focus your development on a certain part. Guards that don't belong to a group are considered global and are always run.
224
- * `#callback`: allows you to execute arbitrary code before or after any of the `start`, `stop`, `reload`, `run_all` and `run_on_change` guards' method. You can even insert more hooks inside these methods. Please [checkout the Wiki page](https://github.com/guard/guard/wiki/Hooks-and-callbacks) for more details.
225
- * `#ignore_paths`: allows you to ignore top level directories altogether. This comes is handy when you have large amounts of non-source data in you project. By default .bundle, .git, log, tmp, and vendor are ignored. Currently it is only possible to ignore the immediate descendants of the watched directory.
226
-
227
- Example:
228
-
229
- ignore_paths 'foo', 'bar'
230
-
231
- group 'backend' do
232
- guard 'bundler' do
233
- watch('Gemfile')
234
- end
235
-
236
- guard 'rspec', :cli => '--color --format doc' do
237
- # Regexp watch patterns are matched with Regexp#match
238
- watch(%r{^spec/.+_spec\.rb$})
239
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
240
- watch(%r{^spec/models/.+\.rb$}) { ["spec/models", "spec/acceptance"] }
241
- watch(%r{^spec/.+\.rb$}) { `say hello` }
242
-
243
- # String watch patterns are matched with simple '=='
244
- watch('spec/spec_helper.rb') { "spec" }
245
- end
246
- end
247
-
248
- group 'frontend' do
249
- guard 'coffeescript', :output => 'public/javascripts/compiled' do
250
- watch(%r{^app/coffeescripts/.+\.coffee$})
251
- end
252
-
253
- guard 'livereload' do
254
- watch(%r{^app/.+\.(erb|haml)$})
255
- end
256
- end
257
-
258
- Using a Guardfile without the `guard` binary
259
- --------------------------------------------
260
-
261
- The Guardfile DSL can also be used in a programmatic fashion by calling directly `Guard::Dsl.evaluate_guardfile`.
262
- Available options are as follow:
263
-
264
- * `:guardfile` - The path to a valid Guardfile.
265
- * `:guardfile_contents` - A string representing the content of a valid Guardfile
266
-
267
- Remember, without any options given, Guard will look for a Guardfile in your current directory and if it does not find one, it will look for it in your `$HOME` directory.
268
-
269
- For instance, you could use it as follow:
270
-
271
- gem 'guard'
272
- require 'guard'
273
-
274
- Guard.setup
275
-
276
- Guard::Dsl.evaluate_guardfile(:guardfile => '/your/custom/path/to/a/valid/Guardfile')
277
- # or
278
- Guard::Dsl.evaluate_guardfile(:guardfile_contents => "
279
- guard 'rspec' do
280
- watch(%r{^spec/.+_spec\.rb$})
281
- end
282
- ")
283
-
284
- ### Listing defined guards/groups for the current project
285
-
286
- You can list the defined groups and guards for the current Guardfile from the command line using `guard show` or `guard -T`:
287
-
288
- $ guard -T
289
-
290
- (global):
291
- shell
292
- Group backend:
293
- bundler
294
- rspec: cli => "--color --format doc"
295
- Group frontend:
296
- coffeescript: output => "public/javascripts/compiled"
297
- livereload
298
-
299
- User config file
300
- ----------------
301
-
302
- If a `.guard.rb` is found in your home directory, it will be appended to
303
- the Guardfile. This can be used for tasks you want guard to handle but
304
- other users probably don't. For example, indexing your source tree with
305
- [Ctags](http://ctags.sourceforge.net):
306
-
307
- guard 'shell' do
308
- watch(%r{^(?:app|lib)/.+\.rb$}) { `ctags -R` }
309
- end
310
-
311
- Create a new guard
312
- ------------------
313
-
314
- Creating a new guard is very easy, just create a new gem (`bundle gem` if you use Bundler) with this basic structure:
315
-
316
- .travis.yml # bonus point!
317
- CHANGELOG.md # bonus point!
318
- Gemfile
319
- guard-name.gemspec
320
- Guardfile
321
- lib/
322
- guard/
323
- guard-name/
324
- templates/
325
- Guardfile # needed for `guard init <guard-name>`
326
- version.rb
327
- guard-name.rb
328
- test/ # or spec/
329
- README.md
330
-
331
- `Guard::GuardName` (in `lib/guard/guard-name.rb`) must inherit from
332
- [Guard::Guard](http://rubydoc.info/github/guard/guard/master/Guard/Guard) and should overwrite at least one of
333
- the basic `Guard::Guard` task methods.
334
-
335
- Here is an example scaffold for `lib/guard/guard-name.rb`:
336
-
337
- require 'guard'
338
- require 'guard/guard'
339
-
340
- module Guard
341
- class GuardName < Guard
342
-
343
- # Initialize a Guard.
344
- # @param [Array<Guard::Watcher>] watchers the Guard file watchers
345
- # @param [Hash] options the custom Guard options
346
- def initialize(watchers = [], options = {})
347
- super
348
- end
349
-
350
- # Call once when Guard starts. Please override initialize method to init stuff.
351
- # @raise [:task_has_failed] when start has failed
352
- def start
353
- end
354
-
355
- # Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
356
- # @raise [:task_has_failed] when stop has failed
357
- def stop
358
- end
359
-
360
- # Called when `reload|r|z + enter` is pressed.
361
- # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
362
- # @raise [:task_has_failed] when reload has failed
363
- def reload
364
- end
365
-
366
- # Called when just `enter` is pressed
367
- # This method should be principally used for long action like running all specs/tests/...
368
- # @raise [:task_has_failed] when run_all has failed
369
- def run_all
370
- end
371
-
372
- # Called on file(s) modifications that the Guard watches.
373
- # @param [Array<String>] paths the changes files or paths
374
- # @raise [:task_has_failed] when run_on_change has failed
375
- def run_on_change(paths)
376
- end
377
-
378
- # Called on file(s) deletions that the Guard watches.
379
- # @param [Array<String>] paths the deleted files or paths
380
- # @raise [:task_has_failed] when run_on_change has failed
381
- def run_on_deletion(paths)
382
- end
383
-
384
- end
385
- end
386
-
387
- Please take a look at the [existing guards' source code](https://github.com/guard/guard/wiki/List-of-available-Guards)
388
- for more concrete example and inspiration.
389
-
390
- Alternatively, a new guard can be added inline to a Guardfile with this basic structure:
391
-
392
- require 'guard/guard'
393
-
394
- module ::Guard
395
- class InlineGuard < ::Guard::Guard
396
- def run_all
397
- end
398
-
399
- def run_on_change(paths)
400
- end
401
- end
402
- end
403
-
404
- Here is a very cool example by [@avdi](https://github.com/avdi) : http://avdi.org/devblog/2011/06/15/a-guardfile-for-redis
405
-
406
- Development
407
- -----------
408
-
409
- * Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/guard/master/frames).
410
- * Source hosted at [GitHub](https://github.com/guard/guard).
411
- * Report issues and feature requests to [GitHub Issues](https://github.com/guard/guard/issues).
412
-
413
- Pull requests are very welcome! Please try to follow these simple "rules", though:
414
-
415
- - Please create a topic branch for every separate change you make;
416
- - Make sure your patches are well tested;
417
- - Update the README (if applicable);
418
- - Update the CHANGELOG (maybe not for a typo but don't hesitate!);
419
- - Please **do not change** the version number.
420
-
421
- For questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard` (irc.freenode.net).
422
-
423
- Author
424
- ------
425
-
426
- [Thibaud Guillaume-Gentil](https://github.com/thibaudgg)
427
-
428
- Contributors
429
- ------------
430
-
431
- https://github.com/guard/guard/contributors
1
+ Guard [![Build Status](https://secure.travis-ci.org/guard/guard.png)](http://travis-ci.org/guard/guard)
2
+ =====
3
+
4
+ Guard is a command line tool that easily handle events on files modifications.
5
+
6
+ If you have any questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard` (irc.freenode.net).
7
+
8
+ Features
9
+ --------
10
+
11
+ * [FSEvent](http://en.wikipedia.org/wiki/FSEvents) support on Mac OS X 10.5+ (without RubyCocoa!, [rb-fsevent gem, >= 0.3.5](https://rubygems.org/gems/rb-fsevent) required).
12
+ * [Inotify](http://en.wikipedia.org/wiki/Inotify) support on Linux ([rb-inotify gem, >= 0.5.1](https://rubygems.org/gems/rb-inotify) required).
13
+ * [Directory Change Notification](http://msdn.microsoft.com/en-us/library/aa365261\(VS.85\).aspx) support on Windows ([rb-fchange, >= 0.0.2](https://rubygems.org/gems/rb-fchange) required).
14
+ * Polling on the other operating systems (help us to support more OS).
15
+ * Automatic & Super fast (when polling is not used) files modifications detection (even new files are detected).
16
+ * Visual notifications on Mac OSX ([Growl](http://growl.info)), Linux ([Libnotify](http://developer.gnome.org/libnotify)) and Windows ([Notifu](http://www.paralint.com/projects/notifu)).
17
+ * Tested against Ruby 1.8.7, 1.9.2, REE and the latest versions of JRuby & Rubinius.
18
+
19
+ Screencast
20
+ ----------
21
+
22
+ Ryan Bates made a Railscast on Guard, you can view it here: [http://railscasts.com/episodes/264-guard](http://railscasts.com/episodes/264-guard)
23
+
24
+ Install
25
+ -------
26
+
27
+ Add Guard to your `Gemfile`:
28
+
29
+ group :development do
30
+ gem 'guard'
31
+ gem 'rb-inotify', :require => false
32
+ gem 'rb-fsevent', :require => false
33
+ gem 'rb-fchange', :require => false
34
+ end
35
+
36
+ and install it via Bundler:
37
+
38
+ $ bundle
39
+
40
+ Generate an empty Guardfile with:
41
+
42
+ $ guard init
43
+
44
+ You may optionally place a .Guardfile in your home directory to use it across multiple projects.
45
+ Also note that if a `.guard.rb` is found in your home directory, it will be appended to the Guardfile.
46
+
47
+ Add the guards you need to your Guardfile (see the existing guards below).
48
+
49
+ Now, be sure to read the particular instructions for your operating system: [Mac OS X](#mac) | [Linux](#linux) | [Windows](#win)
50
+
51
+ <a name="mac" />
52
+
53
+ ### On Mac OS X
54
+
55
+ Install the rb-fsevent gem for [FSEvent](http://en.wikipedia.org/wiki/FSEvents) support:
56
+
57
+ $ gem install rb-fsevent
58
+
59
+ You have three possibilities for getting Growl support:
60
+
61
+ Use the [growl_notify gem](https://rubygems.org/gems/growl_notify):
62
+
63
+ $ gem install growl_notify
64
+
65
+ The `growl_notify` gem is compatible with Growl >= 1.3 and uses AppleScript to send Growl notifications.
66
+ The gem needs a native C extension to make use of AppleScript and does not run on JRuby and MacRuby.
67
+
68
+ Use the [ruby_gntp gem](https://github.com/snaka/ruby_gntp):
69
+
70
+ $ gem install ruby_gntp
71
+
72
+ The `ruby_gntp` gem is compatible with Growl >= 1.3 and uses the Growl Notification Transport Protocol to send Growl
73
+ notifications. Guard supports multiple notification channels for customizing each notification type, but it's limited
74
+ to the local host currently.
75
+
76
+ Use the [growl gem](https://rubygems.org/gems/growl):
77
+
78
+ $ gem install growl
79
+
80
+ The `growl` gem is compatible with all versions of Growl and uses a command line tool [growlnotify](http://growl.info/extras.php#growlnotify)
81
+ that must be separately downloaded and installed. You can also install it with HomeBrew:
82
+
83
+ $ brew install growlnotify
84
+
85
+ Finally you have to add your Growl library of choice to your Gemfile:
86
+
87
+ gem 'rb-fsevent'
88
+ gem 'growl_notify' # or gem 'ruby_gntp' or gem 'growl'
89
+
90
+ Have a look at the [Guard Wiki](https://github.com/guard/guard/wiki/Which-Growl-library-should-I-use) for more information.
91
+
92
+ <a name="linux" />
93
+
94
+ ### On Linux
95
+
96
+ Install the [rb-inotify gem](https://rubygems.org/gems/rb-inotify) for [inotify](http://en.wikipedia.org/wiki/Inotify) support:
97
+
98
+ $ gem install rb-inotify
99
+
100
+ Install the [libnotify gem](https://rubygems.org/gems/libnotify) if you want visual notification support:
101
+
102
+ $ gem install libnotify
103
+
104
+ And add them to your Gemfile:
105
+
106
+ gem 'rb-inotify'
107
+ gem 'libnotify'
108
+
109
+ <a name="win" />
110
+
111
+ ### On Windows
112
+
113
+ Install the [rb-fchange gem](https://rubygems.org/gems/rb-fchange) for [Directory Change Notification](http://msdn.microsoft.com/en-us/library/aa365261\(VS.85\).aspx) support:
114
+
115
+ $ gem install rb-fchange
116
+
117
+ Install the [win32console gem](https://rubygems.org/gems/win32console) if you want colors in your terminal:
118
+
119
+ $ gem install win32console
120
+
121
+ Install the [rb-notifu gem](https://rubygems.org/gems/rb-notifu) if you want visual notification support:
122
+
123
+ $ gem install rb-notifu
124
+
125
+ And add them to your Gemfile:
126
+
127
+ gem 'rb-fchange'
128
+ gem 'rb-notifu'
129
+ gem 'win32console'
130
+
131
+ Usage
132
+ -----
133
+
134
+ Just launch Guard inside your Ruby / Rails project with:
135
+
136
+ $ guard [start]
137
+
138
+ or if you use Bundler, to run the Guard executable specific to your bundle:
139
+
140
+ $ bundle exec guard [start]
141
+
142
+ Guard will look for a Guardfile in your current directory. If it does not find one, it will look in your `$HOME` directory for a .Guardfile.
143
+
144
+ Command line options
145
+ --------------------
146
+
147
+ ### `-c`/`--clear` option
148
+
149
+ Shell can be cleared after each change:
150
+
151
+ $ guard --clear
152
+ $ guard -c # shortcut
153
+
154
+ ### `-n`/`--notify` option
155
+
156
+ Notifications (growl/libnotify) can be disabled:
157
+
158
+ $ guard --notify false
159
+ $ guard -n f # shortcut
160
+
161
+ Notifications can also be disabled globally by setting a `GUARD_NOTIFY` environment variable to `false`
162
+
163
+ ### `-g`/`--group` option
164
+
165
+ Only certain guards groups can be run (see the Guardfile DSL below for creating groups):
166
+
167
+ $ guard --group group_name another_group_name
168
+ $ guard -g group_name another_group_name # shortcut
169
+
170
+ ### `-d`/`--debug` option
171
+
172
+ Guard can be run in debug mode:
173
+
174
+ $ guard --debug
175
+ $ guard -d # shortcut
176
+
177
+ ### `-w`/`--watchdir` option
178
+
179
+ Guard can watch in any directory (instead of the current directory):
180
+
181
+ $ guard --watchdir ~/your/fancy/project
182
+ $ guard -w ~/your/fancy/project # shortcut
183
+
184
+ ### `-G`/`--guardfile` option
185
+
186
+ Guard can use a Guardfile not located in the current directory:
187
+
188
+ $ guard --guardfile ~/.your_global_guardfile
189
+ $ guard -G ~/.your_global_guardfile # shortcut
190
+
191
+ ### `-A`/`--watch-all-modifications` option
192
+
193
+ Guard can optionally watch all file modifications like moves or deletions with:
194
+
195
+ $ guard start -A
196
+ $ guard start --watch-all-modifications
197
+
198
+ ### `-i`/`--no-interactions` option
199
+
200
+ Turn off completely any Guard terminal [interactions](#interactions) with:
201
+
202
+ $ guard start -A
203
+ $ guard start --watch-all-modifications
204
+
205
+ An exhaustive list of options is available with:
206
+
207
+ $ guard help [TASK]
208
+
209
+ <a name="interactions" />
210
+
211
+ Interactions
212
+ ------------
213
+
214
+ **From version >= 0.7.0 Posix Signal handlers are no more used to interact with Guard. If you're using a version < 0.7, please refer to the [README in the v0.6 branch](https://github.com/guard/guard/blob/v0.6/README.md).**
215
+
216
+ When Guard do nothing you can interact with by entering a command + hitting return/enter:
217
+
218
+ * `stop`: `stop|quit|exit|s|q|e + return` - Calls each guard's `#stop` method, in the same order they are declared in the Guardfile, and then quits Guard itself.
219
+ * `reload`: `reload|r|z + return` - Calls each guard's `#reload` method, in the same order they are declared in the Guardfile.
220
+ * `pause`: `pause|p + return` - Toggle files modification listening. Useful when switching git branches.
221
+ * `run_all`: `just return (no commands)` - Calls each guard's `#run_all` method, in the same order they are declared in the Guardfile.
222
+
223
+ `reload` and `run_all` actions can be scoped to only run on a certain guard or group. Examples:
224
+
225
+ * `backend reload + return` - Call only each guard's `#reload` method on backend group.
226
+ * `rspec + return` - Call only rspec guard's `#run_all` method.
227
+
228
+ Available Guards
229
+ ----------------
230
+
231
+ A list of the available guards is present [in the wiki](https://github.com/guard/guard/wiki/List-of-available-Guards).
232
+
233
+ ### Add a guard to your Guardfile
234
+
235
+ Add it to your Gemfile (inside the `development` group):
236
+
237
+ gem '<guard-name>'
238
+
239
+ You can list all guards installed on your system with:
240
+
241
+ $ guard list
242
+
243
+ Insert default guard's definition to your Guardfile by running this command:
244
+
245
+ $ guard init <guard-name>
246
+
247
+ You are good to go, or you can modify your guards' definition to suit your needs.
248
+
249
+ Guardfile DSL
250
+ -------------
251
+
252
+ The Guardfile DSL consists of the following methods:
253
+
254
+ * `#guard` - Allows you to add a guard with an optional hash of options.
255
+ * `#watch` - Allows you to define which files are supervised by a guard. An optional block can be added to overwrite the paths sent to the guard's `#run_on_change` method or to launch any arbitrary command.
256
+ * `#group` - Allows you to group several guards together. Groups to be run can be specified with the Guard DSL option `--group` (or `-g`). This comes in handy especially when you have a huge Guardfile and want to focus your development on a certain part. Guards that don't belong to a group are considered global and are always run.
257
+ * `#callback` - Allows you to execute arbitrary code before or after any of the `start`, `stop`, `reload`, `run_all` and `run_on_change` guards' method. You can even insert more hooks inside these methods. Please [checkout the Wiki page](https://github.com/guard/guard/wiki/Hooks-and-callbacks) for more details.
258
+ * `#ignore_paths` - Allows you to ignore top level directories altogether. This comes is handy when you have large amounts of non-source data in you project. By default .bundle, .git, log, tmp, and vendor are ignored. Currently it is only possible to ignore the immediate descendants of the watched directory.
259
+
260
+ Example:
261
+
262
+ ignore_paths 'foo', 'bar'
263
+
264
+ group 'backend' do
265
+ guard 'bundler' do
266
+ watch('Gemfile')
267
+ end
268
+
269
+ guard 'rspec', :cli => '--color --format doc' do
270
+ # Regexp watch patterns are matched with Regexp#match
271
+ watch(%r{^spec/.+_spec\.rb$})
272
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
273
+ watch(%r{^spec/models/.+\.rb$}) { ["spec/models", "spec/acceptance"] }
274
+ watch(%r{^spec/.+\.rb$}) { `say hello` }
275
+
276
+ # String watch patterns are matched with simple '=='
277
+ watch('spec/spec_helper.rb') { "spec" }
278
+ end
279
+ end
280
+
281
+ group 'frontend' do
282
+ guard 'coffeescript', :output => 'public/javascripts/compiled' do
283
+ watch(%r{^app/coffeescripts/.+\.coffee$})
284
+ end
285
+
286
+ guard 'livereload' do
287
+ watch(%r{^app/.+\.(erb|haml)$})
288
+ end
289
+ end
290
+
291
+ Using a Guardfile without the `guard` binary
292
+ --------------------------------------------
293
+
294
+ The Guardfile DSL can also be used in a programmatic fashion by calling directly `Guard::Dsl.evaluate_guardfile`.
295
+ Available options are as follow:
296
+
297
+ * `:guardfile` - The path to a valid Guardfile.
298
+ * `:guardfile_contents` - A string representing the content of a valid Guardfile
299
+
300
+ Remember, without any options given, Guard will look for a Guardfile in your current directory and if it does not find one, it will look for it in your `$HOME` directory.
301
+
302
+ For instance, you could use it as follow:
303
+
304
+ gem 'guard'
305
+ require 'guard'
306
+
307
+ Guard.setup
308
+
309
+ Guard::Dsl.evaluate_guardfile(:guardfile => '/your/custom/path/to/a/valid/Guardfile')
310
+ # or
311
+ Guard::Dsl.evaluate_guardfile(:guardfile_contents => "
312
+ guard 'rspec' do
313
+ watch(%r{^spec/.+_spec\.rb$})
314
+ end
315
+ ")
316
+
317
+ ### Listing defined guards/groups for the current project
318
+
319
+ You can list the defined groups and guards for the current Guardfile from the command line using `guard show` or `guard -T`:
320
+
321
+ $ guard -T
322
+
323
+ (global):
324
+ shell
325
+ Group backend:
326
+ bundler
327
+ rspec: cli => "--color --format doc"
328
+ Group frontend:
329
+ coffeescript: output => "public/javascripts/compiled"
330
+ livereload
331
+
332
+ User config file
333
+ ----------------
334
+
335
+ If a `.guard.rb` is found in your home directory, it will be appended to
336
+ the Guardfile. This can be used for tasks you want guard to handle but
337
+ other users probably don't. For example, indexing your source tree with
338
+ [Ctags](http://ctags.sourceforge.net):
339
+
340
+ guard 'shell' do
341
+ watch(%r{^(?:app|lib)/.+\.rb$}) { `ctags -R` }
342
+ end
343
+
344
+ Create a new guard
345
+ ------------------
346
+
347
+ Creating a new guard is very easy, just create a new gem (`bundle gem` if you use Bundler) with this basic structure:
348
+
349
+ .travis.yml # bonus point!
350
+ CHANGELOG.md # bonus point!
351
+ Gemfile
352
+ guard-name.gemspec
353
+ Guardfile
354
+ lib/
355
+ guard/
356
+ guard-name/
357
+ templates/
358
+ Guardfile # needed for `guard init <guard-name>`
359
+ version.rb
360
+ guard-name.rb
361
+ test/ # or spec/
362
+ README.md
363
+
364
+ `Guard::GuardName` (in `lib/guard/guard-name.rb`) must inherit from
365
+ [Guard::Guard](http://rubydoc.info/github/guard/guard/master/Guard/Guard) and should overwrite at least one of
366
+ the basic `Guard::Guard` task methods.
367
+
368
+ Here is an example scaffold for `lib/guard/guard-name.rb`:
369
+
370
+ require 'guard'
371
+ require 'guard/guard'
372
+
373
+ module Guard
374
+ class GuardName < Guard
375
+
376
+ # Initialize a Guard.
377
+ # @param [Array<Guard::Watcher>] watchers the Guard file watchers
378
+ # @param [Hash] options the custom Guard options
379
+ def initialize(watchers = [], options = {})
380
+ super
381
+ end
382
+
383
+ # Call once when Guard starts. Please override initialize method to init stuff.
384
+ # @raise [:task_has_failed] when start has failed
385
+ def start
386
+ end
387
+
388
+ # Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
389
+ # @raise [:task_has_failed] when stop has failed
390
+ def stop
391
+ end
392
+
393
+ # Called when `reload|r|z + enter` is pressed.
394
+ # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
395
+ # @raise [:task_has_failed] when reload has failed
396
+ def reload
397
+ end
398
+
399
+ # Called when just `enter` is pressed
400
+ # This method should be principally used for long action like running all specs/tests/...
401
+ # @raise [:task_has_failed] when run_all has failed
402
+ def run_all
403
+ end
404
+
405
+ # Called on file(s) modifications that the Guard watches.
406
+ # @param [Array<String>] paths the changes files or paths
407
+ # @raise [:task_has_failed] when run_on_change has failed
408
+ def run_on_change(paths)
409
+ end
410
+
411
+ # Called on file(s) deletions that the Guard watches.
412
+ # @param [Array<String>] paths the deleted files or paths
413
+ # @raise [:task_has_failed] when run_on_change has failed
414
+ def run_on_deletion(paths)
415
+ end
416
+
417
+ end
418
+ end
419
+
420
+ Please take a look at the [existing guards' source code](https://github.com/guard/guard/wiki/List-of-available-Guards)
421
+ for more concrete example and inspiration.
422
+
423
+ Alternatively, a new guard can be added inline to a Guardfile with this basic structure:
424
+
425
+ require 'guard/guard'
426
+
427
+ module ::Guard
428
+ class InlineGuard < ::Guard::Guard
429
+ def run_all
430
+ end
431
+
432
+ def run_on_change(paths)
433
+ end
434
+ end
435
+ end
436
+
437
+ Here is a very cool example by [@avdi](https://github.com/avdi) : [http://avdi.org/devblog/2011/06/15/a-guardfile-for-redis](http://avdi.org/devblog/2011/06/15/a-guardfile-for-redis)
438
+
439
+ Development
440
+ -----------
441
+
442
+ * Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/guard/master/frames).
443
+ * Source hosted at [GitHub](https://github.com/guard/guard).
444
+ * Report issues and feature requests to [GitHub Issues](https://github.com/guard/guard/issues).
445
+
446
+ Pull requests are very welcome! Please try to follow these simple "rules", though:
447
+
448
+ - Please create a topic branch for every separate change you make;
449
+ - Make sure your patches are well tested;
450
+ - Update the README (if applicable);
451
+ - Update the CHANGELOG (maybe not for a typo but don't hesitate!);
452
+ - Please **do not change** the version number.
453
+
454
+ For questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard` (irc.freenode.net).
455
+
456
+ Author
457
+ ------
458
+
459
+ [Thibaud Guillaume-Gentil](https://github.com/thibaudgg)
460
+
461
+ Contributors
462
+ ------------
463
+
464
+ [https://github.com/guard/guard/contributors](https://github.com/guard/guard/contributors)