guard 0.7.0.rc1 → 0.7.0

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,487 +1,487 @@
1
- Guard [![Build Status](http://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
- ``` bash
30
- $ gem install guard
31
- ```
32
-
33
- Or add it to your Gemfile (inside the `development` group):
34
-
35
- ``` ruby
36
- gem 'guard'
37
- ```
38
-
39
- and install it via Bundler:
40
-
41
- ``` bash
42
- $ bundle install
43
- ```
44
-
45
- Generate an empty Guardfile with:
46
-
47
- ``` bash
48
- $ guard init
49
- ```
50
-
51
- You may optionally place a .Guardfile in your home directory to use it across multiple projects.
52
- Also note that if a `.guard.rb` is found in your home directory, it will be appended to the Guardfile.
53
-
54
- Add the guards you need to your Guardfile (see the existing guards below).
55
-
56
- ### On Mac OS X
57
-
58
- Install the rb-fsevent gem for [FSEvent](http://en.wikipedia.org/wiki/FSEvents) support:
59
-
60
- ``` bash
61
- $ gem install rb-fsevent
62
- ```
63
-
64
- You have two possibilities:
65
-
66
- Use the [growl_notify gem](https://rubygems.org/gems/growl_notify) (recommended):
67
-
68
- ``` bash
69
- $ gem install growl_notify
70
- ```
71
-
72
- Use the [growlnotify](http://growl.info/extras.php#growlnotify) (cli tool for growl) + the [growl gem](https://rubygems.org/gems/growl).
73
-
74
- ``` bash
75
- $ brew install growlnotify
76
- $ gem install growl
77
- ```
78
-
79
- And add them to your Gemfile:
80
-
81
- ``` ruby
82
- gem 'rb-fsevent'
83
- gem 'growl_notify' # or gem 'growl'
84
- ```
85
-
86
- The difference between growl and growl_notify is that growl_notify uses AppleScript to
87
- display a message, whereas growl uses the `growlnotify` command. In general the AppleScript
88
- approach is preferred, but you may also use the older growl gem. Have a look at the
89
- [Guard Wiki](https://github.com/guard/guard/wiki/Use-growl_notify-or-growl-gem) for more information.
90
-
91
- ### On Linux
92
-
93
- Install the [rb-inotify gem](https://rubygems.org/gems/rb-inotify) for [inotify](http://en.wikipedia.org/wiki/Inotify) support:
94
-
95
- ``` bash
96
- $ gem install rb-inotify
97
- ```
98
-
99
- Install the [libnotify gem](https://rubygems.org/gems/libnotify) if you want visual notification support:
100
-
101
- ``` bash
102
- $ gem install libnotify
103
- ```
104
-
105
- And add them to your Gemfile:
106
-
107
- ``` ruby
108
- gem 'rb-inotify'
109
- gem 'libnotify'
110
- ```
111
-
112
- ### On Windows
113
-
114
- 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:
115
-
116
- ``` bash
117
- $ gem install rb-fchange
118
- ```
119
-
120
- Install the [win32console gem](https://rubygems.org/gems/win32console) if you want colors in your terminal:
121
-
122
- ``` bash
123
- $ gem install win32console
124
- ```
125
-
126
- Install the [rb-notifu gem](https://rubygems.org/gems/rb-notifu) if you want visual notification support:
127
-
128
- ``` bash
129
- $ gem install rb-notifu
130
- ```
131
-
132
- And add them to your Gemfile:
133
-
134
- ``` ruby
135
- gem 'rb-fchange'
136
- gem 'rb-notifu'
137
- gem 'win32console'
138
- ```
139
-
140
- Usage
141
- -----
142
-
143
- Just launch Guard inside your Ruby / Rails project with:
144
-
145
- ``` bash
146
- $ guard [start]
147
- ```
148
-
149
- or if you use Bundler, to run the Guard executable specific to your bundle:
150
-
151
- ``` bash
152
- $ bundle exec guard [start]
153
- ```
154
-
155
- 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.
156
-
157
- Command line options
158
- --------------------
159
-
160
- ### `-c`/`--clear` option
161
-
162
- Shell can be cleared after each change:
163
-
164
- ``` bash
165
- $ guard --clear
166
- $ guard -c # shortcut
167
- ```
168
-
169
- ### `-n`/`--notify` option
170
-
171
- Notifications (growl/libnotify) can be disabled:
172
-
173
- ``` bash
174
- $ guard --notify false
175
- $ guard -n f # shortcut
176
- ```
177
-
178
- Notifications can also be disabled globally by setting a `GUARD_NOTIFY` environment variable to `false`
179
-
180
- ### `-g`/`--group` option
181
-
182
- Only certain guards groups can be run (see the Guardfile DSL below for creating groups):
183
-
184
- ``` bash
185
- $ guard --group group_name another_group_name
186
- $ guard -g group_name another_group_name # shortcut
187
- ```
188
-
189
- ### `-d`/`--debug` option
190
-
191
- Guard can be run in debug mode:
192
-
193
- ``` bash
194
- $ guard --debug
195
- $ guard -d # shortcut
196
- ```
197
-
198
- ### `-w`/`--watchdir` option
199
-
200
- Guard can watch in any directory (instead of the current directory):
201
-
202
- ``` bash
203
- $ guard --watchdir ~/your/fancy/project
204
- $ guard -w ~/your/fancy/project # shortcut
205
- ```
206
-
207
- ### `-G`/`--guardfile` option
208
-
209
- Guard can use a Guardfile not located in the current directory:
210
-
211
- ``` bash
212
- $ guard --guardfile ~/.your_global_guardfile
213
- $ guard -G ~/.your_global_guardfile # shortcut
214
- ```
215
-
216
- An exhaustive list of options is available with:
217
-
218
- ``` bash
219
- $ guard help [TASK]
220
- ```
221
-
222
- Interactions
223
- ------------
224
-
225
- **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).**
226
-
227
- When Guard do nothing you can interact with by entering a command + hitting enter:
228
-
229
- * `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.
230
- * `reload|r|z + enter` - Calls each guard's `#reload` method, in the same order they are declared in the Guardfile.
231
- * `pause|p + enter` - Toggle files modification listening. Useful when switching git branches.
232
- * `just enter (no commands)` - Calls each guard's `#run_all` method, in the same order they are declared in the Guardfile.
233
-
234
- Available Guards
235
- ----------------
236
-
237
- A list of the available guards is present [in the wiki](https://github.com/guard/guard/wiki/List-of-available-Guards).
238
-
239
- ### Add a guard to your Guardfile
240
-
241
- Add it to your Gemfile (inside the `development` group):
242
-
243
- ``` ruby
244
- gem '<guard-name>'
245
- ```
246
-
247
- You can list all guards installed on your system with:
248
-
249
- ``` bash
250
- $ guard list
251
- ```
252
-
253
- Insert default guard's definition to your Guardfile by running this command:
254
-
255
- ``` bash
256
- $ guard init <guard-name>
257
- ```
258
-
259
- You are good to go, or you can modify your guards' definition to suit your needs.
260
-
261
- Guardfile DSL
262
- -------------
263
-
264
- The Guardfile DSL consists of the following methods:
265
-
266
- * `#guard`: allows you to add a guard with an optional hash of options.
267
- * `#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.
268
- * `#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.
269
- * `#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.
270
- * `#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.
271
-
272
- Example:
273
-
274
- ``` ruby
275
- ignore_paths 'foo', 'bar'
276
-
277
- group 'backend' do
278
- guard 'bundler' do
279
- watch('Gemfile')
280
- end
281
-
282
- guard 'rspec', :cli => '--color --format doc' do
283
- # Regexp watch patterns are matched with Regexp#match
284
- watch(%r{^spec/.+_spec\.rb$})
285
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
286
- watch(%r{^spec/models/.+\.rb$}) { ["spec/models", "spec/acceptance"] }
287
- watch(%r{^spec/.+\.rb$}) { `say hello` }
288
-
289
- # String watch patterns are matched with simple '=='
290
- watch('spec/spec_helper.rb') { "spec" }
291
- end
292
- end
293
-
294
- group 'frontend' do
295
- guard 'coffeescript', :output => 'public/javascripts/compiled' do
296
- watch(%r{^app/coffeescripts/.+\.coffee$})
297
- end
298
-
299
- guard 'livereload' do
300
- watch(%r{^app/.+\.(erb|haml)$})
301
- end
302
- end
303
- ```
304
-
305
- Using a Guardfile without the `guard` binary
306
- --------------------------------------------
307
-
308
- The Guardfile DSL can also be used in a programmatic fashion by calling directly `Guard::Dsl.evaluate_guardfile`.
309
- Available options are as follow:
310
-
311
- * `:guardfile` - The path to a valid Guardfile.
312
- * `:guardfile_contents` - A string representing the content of a valid Guardfile
313
-
314
- 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.
315
-
316
- For instance, you could use it as follow:
317
-
318
- ``` ruby
319
- gem 'guard'
320
- require 'guard'
321
-
322
- Guard.setup
323
-
324
- Guard::Dsl.evaluate_guardfile(:guardfile => '/your/custom/path/to/a/valid/Guardfile')
325
- # or
326
- Guard::Dsl.evaluate_guardfile(:guardfile_contents => "
327
- guard 'rspec' do
328
- watch(%r{^spec/.+_spec\.rb$})
329
- end
330
- ")
331
- ```
332
-
333
- ### Listing defined guards/groups for the current project
334
-
335
- You can list the defined groups and guards for the current Guardfile from the command line using `guard show` or `guard -T`:
336
-
337
- ``` bash
338
- # guard -T
339
-
340
- (global):
341
- shell
342
- Group backend:
343
- bundler
344
- rspec: cli => "--color --format doc"
345
- Group frontend:
346
- coffeescript: output => "public/javascripts/compiled"
347
- livereload
348
- ```
349
-
350
- User config file
351
- ----------------
352
-
353
- If a `.guard.rb` is found in your home directory, it will be appended to
354
- the Guardfile. This can be used for tasks you want guard to handle but
355
- other users probably don't. For example, indexing your source tree with
356
- [Ctags](http://ctags.sourceforge.net):
357
-
358
- ``` ruby
359
- guard 'shell' do
360
- watch(%r{^(?:app|lib)/.+\.rb$}) { `ctags -R` }
361
- end
362
- ```
363
-
364
- Create a new guard
365
- ------------------
366
-
367
- Creating a new guard is very easy, just create a new gem (`bundle gem` if you use Bundler) with this basic structure:
368
-
369
- ```
370
- .travis.yml # bonus point!
371
- CHANGELOG.md # bonus point!
372
- Gemfile
373
- guard-name.gemspec
374
- Guardfile
375
- lib/
376
- guard/
377
- guard-name/
378
- templates/
379
- Guardfile # needed for `guard init <guard-name>`
380
- version.rb
381
- guard-name.rb
382
- test/ # or spec/
383
- README.md
384
- ```
385
-
386
- `Guard::GuardName` (in `lib/guard/guard-name.rb`) must inherit from `Guard::Guard` and should overwrite at least one of the five basic `Guard::Guard` instance methods.
387
-
388
- Here is an example scaffold for `lib/guard/guard-name.rb`:
389
-
390
- ``` ruby
391
- require 'guard'
392
- require 'guard/guard'
393
-
394
- module Guard
395
- class GuardName < Guard
396
-
397
- def initialize(watchers=[], options={})
398
- super
399
- # init stuff here, thx!
400
- end
401
-
402
- # =================
403
- # = Guard methods =
404
- # =================
405
-
406
- # If one of those methods raise an exception, the Guard::GuardName instance
407
- # will be removed from the active guards.
408
-
409
- # Called once when Guard starts
410
- # Please override initialize method to init stuff
411
- def start
412
- true
413
- end
414
-
415
- # Called on Ctrl-C signal (when Guard quits)
416
- def stop
417
- true
418
- end
419
-
420
- # Called on Ctrl-Z signal
421
- # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
422
- def reload
423
- true
424
- end
425
-
426
- # Called on Ctrl-\ signal
427
- # This method should be principally used for long action like running all specs/tests/...
428
- def run_all
429
- true
430
- end
431
-
432
- # Called on file(s) modifications
433
- def run_on_change(paths)
434
- true
435
- end
436
-
437
- end
438
- end
439
- ```
440
-
441
- Please take a look at the [existing guards' source code](https://github.com/guard/guard/wiki/List-of-available-Guards) for more concrete example and inspiration.
442
-
443
- Alternatively, a new guard can be added inline to a Guardfile with this basic structure:
444
-
445
- ``` ruby
446
- require 'guard/guard'
447
-
448
- module ::Guard
449
- class InlineGuard < ::Guard::Guard
450
- def run_all
451
- true
452
- end
453
-
454
- def run_on_change(paths)
455
- true
456
- end
457
- end
458
- end
459
- ```
460
-
461
- Here is a very cool example by [@avdi](https://github.com/avdi) : http://avdi.org/devblog/2011/06/15/a-guardfile-for-redis
462
-
463
- Development
464
- -----------
465
-
466
- * Source hosted at [GitHub](https://github.com/guard/guard).
467
- * Report issues and feature requests to [GitHub Issues](https://github.com/guard/guard/issues).
468
-
469
- Pull requests are very welcome! Please try to follow these simple "rules", though:
470
-
471
- - Please create a topic branch for every separate change you make;
472
- - Make sure your patches are well tested;
473
- - Update the README (if applicable);
474
- - Update the CHANGELOG (maybe not for a typo but don't hesitate!);
475
- - Please **do not change** the version number.
476
-
477
- For questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard` (irc.freenode.net).
478
-
479
- Author
480
- ------
481
-
482
- [Thibaud Guillaume-Gentil](https://github.com/thibaudgg)
483
-
484
- Contributors
485
- ------------
486
-
487
- 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
23
+
24
+ Install
25
+ -------
26
+
27
+ Install the gem:
28
+
29
+ ``` bash
30
+ $ gem install guard
31
+ ```
32
+
33
+ Or add it to your Gemfile (inside the `development` group):
34
+
35
+ ``` ruby
36
+ gem 'guard'
37
+ ```
38
+
39
+ and install it via Bundler:
40
+
41
+ ``` bash
42
+ $ bundle install
43
+ ```
44
+
45
+ Generate an empty Guardfile with:
46
+
47
+ ``` bash
48
+ $ guard init
49
+ ```
50
+
51
+ You may optionally place a .Guardfile in your home directory to use it across multiple projects.
52
+ Also note that if a `.guard.rb` is found in your home directory, it will be appended to the Guardfile.
53
+
54
+ Add the guards you need to your Guardfile (see the existing guards below).
55
+
56
+ ### On Mac OS X
57
+
58
+ Install the rb-fsevent gem for [FSEvent](http://en.wikipedia.org/wiki/FSEvents) support:
59
+
60
+ ``` bash
61
+ $ gem install rb-fsevent
62
+ ```
63
+
64
+ You have two possibilities:
65
+
66
+ Use the [growl_notify gem](https://rubygems.org/gems/growl_notify) (recommended):
67
+
68
+ ``` bash
69
+ $ gem install growl_notify
70
+ ```
71
+
72
+ Use the [growlnotify](http://growl.info/extras.php#growlnotify) (cli tool for growl) + the [growl gem](https://rubygems.org/gems/growl).
73
+
74
+ ``` bash
75
+ $ brew install growlnotify
76
+ $ gem install growl
77
+ ```
78
+
79
+ And add them to your Gemfile:
80
+
81
+ ``` ruby
82
+ gem 'rb-fsevent'
83
+ gem 'growl_notify' # or gem 'growl'
84
+ ```
85
+
86
+ The difference between growl and growl_notify is that growl_notify uses AppleScript to
87
+ display a message, whereas growl uses the `growlnotify` command. In general the AppleScript
88
+ approach is preferred, but you may also use the older growl gem. Have a look at the
89
+ [Guard Wiki](https://github.com/guard/guard/wiki/Use-growl_notify-or-growl-gem) for more information.
90
+
91
+ ### On Linux
92
+
93
+ Install the [rb-inotify gem](https://rubygems.org/gems/rb-inotify) for [inotify](http://en.wikipedia.org/wiki/Inotify) support:
94
+
95
+ ``` bash
96
+ $ gem install rb-inotify
97
+ ```
98
+
99
+ Install the [libnotify gem](https://rubygems.org/gems/libnotify) if you want visual notification support:
100
+
101
+ ``` bash
102
+ $ gem install libnotify
103
+ ```
104
+
105
+ And add them to your Gemfile:
106
+
107
+ ``` ruby
108
+ gem 'rb-inotify'
109
+ gem 'libnotify'
110
+ ```
111
+
112
+ ### On Windows
113
+
114
+ 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:
115
+
116
+ ``` bash
117
+ $ gem install rb-fchange
118
+ ```
119
+
120
+ Install the [win32console gem](https://rubygems.org/gems/win32console) if you want colors in your terminal:
121
+
122
+ ``` bash
123
+ $ gem install win32console
124
+ ```
125
+
126
+ Install the [rb-notifu gem](https://rubygems.org/gems/rb-notifu) if you want visual notification support:
127
+
128
+ ``` bash
129
+ $ gem install rb-notifu
130
+ ```
131
+
132
+ And add them to your Gemfile:
133
+
134
+ ``` ruby
135
+ gem 'rb-fchange'
136
+ gem 'rb-notifu'
137
+ gem 'win32console'
138
+ ```
139
+
140
+ Usage
141
+ -----
142
+
143
+ Just launch Guard inside your Ruby / Rails project with:
144
+
145
+ ``` bash
146
+ $ guard [start]
147
+ ```
148
+
149
+ or if you use Bundler, to run the Guard executable specific to your bundle:
150
+
151
+ ``` bash
152
+ $ bundle exec guard [start]
153
+ ```
154
+
155
+ 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.
156
+
157
+ Command line options
158
+ --------------------
159
+
160
+ ### `-c`/`--clear` option
161
+
162
+ Shell can be cleared after each change:
163
+
164
+ ``` bash
165
+ $ guard --clear
166
+ $ guard -c # shortcut
167
+ ```
168
+
169
+ ### `-n`/`--notify` option
170
+
171
+ Notifications (growl/libnotify) can be disabled:
172
+
173
+ ``` bash
174
+ $ guard --notify false
175
+ $ guard -n f # shortcut
176
+ ```
177
+
178
+ Notifications can also be disabled globally by setting a `GUARD_NOTIFY` environment variable to `false`
179
+
180
+ ### `-g`/`--group` option
181
+
182
+ Only certain guards groups can be run (see the Guardfile DSL below for creating groups):
183
+
184
+ ``` bash
185
+ $ guard --group group_name another_group_name
186
+ $ guard -g group_name another_group_name # shortcut
187
+ ```
188
+
189
+ ### `-d`/`--debug` option
190
+
191
+ Guard can be run in debug mode:
192
+
193
+ ``` bash
194
+ $ guard --debug
195
+ $ guard -d # shortcut
196
+ ```
197
+
198
+ ### `-w`/`--watchdir` option
199
+
200
+ Guard can watch in any directory (instead of the current directory):
201
+
202
+ ``` bash
203
+ $ guard --watchdir ~/your/fancy/project
204
+ $ guard -w ~/your/fancy/project # shortcut
205
+ ```
206
+
207
+ ### `-G`/`--guardfile` option
208
+
209
+ Guard can use a Guardfile not located in the current directory:
210
+
211
+ ``` bash
212
+ $ guard --guardfile ~/.your_global_guardfile
213
+ $ guard -G ~/.your_global_guardfile # shortcut
214
+ ```
215
+
216
+ An exhaustive list of options is available with:
217
+
218
+ ``` bash
219
+ $ guard help [TASK]
220
+ ```
221
+
222
+ Interactions
223
+ ------------
224
+
225
+ **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).**
226
+
227
+ When Guard do nothing you can interact with by entering a command + hitting enter:
228
+
229
+ * `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.
230
+ * `reload|r|z + enter` - Calls each guard's `#reload` method, in the same order they are declared in the Guardfile.
231
+ * `pause|p + enter` - Toggle files modification listening. Useful when switching git branches.
232
+ * `just enter (no commands)` - Calls each guard's `#run_all` method, in the same order they are declared in the Guardfile.
233
+
234
+ Available Guards
235
+ ----------------
236
+
237
+ A list of the available guards is present [in the wiki](https://github.com/guard/guard/wiki/List-of-available-Guards).
238
+
239
+ ### Add a guard to your Guardfile
240
+
241
+ Add it to your Gemfile (inside the `development` group):
242
+
243
+ ``` ruby
244
+ gem '<guard-name>'
245
+ ```
246
+
247
+ You can list all guards installed on your system with:
248
+
249
+ ``` bash
250
+ $ guard list
251
+ ```
252
+
253
+ Insert default guard's definition to your Guardfile by running this command:
254
+
255
+ ``` bash
256
+ $ guard init <guard-name>
257
+ ```
258
+
259
+ You are good to go, or you can modify your guards' definition to suit your needs.
260
+
261
+ Guardfile DSL
262
+ -------------
263
+
264
+ The Guardfile DSL consists of the following methods:
265
+
266
+ * `#guard`: allows you to add a guard with an optional hash of options.
267
+ * `#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.
268
+ * `#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.
269
+ * `#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.
270
+ * `#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.
271
+
272
+ Example:
273
+
274
+ ``` ruby
275
+ ignore_paths 'foo', 'bar'
276
+
277
+ group 'backend' do
278
+ guard 'bundler' do
279
+ watch('Gemfile')
280
+ end
281
+
282
+ guard 'rspec', :cli => '--color --format doc' do
283
+ # Regexp watch patterns are matched with Regexp#match
284
+ watch(%r{^spec/.+_spec\.rb$})
285
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
286
+ watch(%r{^spec/models/.+\.rb$}) { ["spec/models", "spec/acceptance"] }
287
+ watch(%r{^spec/.+\.rb$}) { `say hello` }
288
+
289
+ # String watch patterns are matched with simple '=='
290
+ watch('spec/spec_helper.rb') { "spec" }
291
+ end
292
+ end
293
+
294
+ group 'frontend' do
295
+ guard 'coffeescript', :output => 'public/javascripts/compiled' do
296
+ watch(%r{^app/coffeescripts/.+\.coffee$})
297
+ end
298
+
299
+ guard 'livereload' do
300
+ watch(%r{^app/.+\.(erb|haml)$})
301
+ end
302
+ end
303
+ ```
304
+
305
+ Using a Guardfile without the `guard` binary
306
+ --------------------------------------------
307
+
308
+ The Guardfile DSL can also be used in a programmatic fashion by calling directly `Guard::Dsl.evaluate_guardfile`.
309
+ Available options are as follow:
310
+
311
+ * `:guardfile` - The path to a valid Guardfile.
312
+ * `:guardfile_contents` - A string representing the content of a valid Guardfile
313
+
314
+ 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.
315
+
316
+ For instance, you could use it as follow:
317
+
318
+ ``` ruby
319
+ gem 'guard'
320
+ require 'guard'
321
+
322
+ Guard.setup
323
+
324
+ Guard::Dsl.evaluate_guardfile(:guardfile => '/your/custom/path/to/a/valid/Guardfile')
325
+ # or
326
+ Guard::Dsl.evaluate_guardfile(:guardfile_contents => "
327
+ guard 'rspec' do
328
+ watch(%r{^spec/.+_spec\.rb$})
329
+ end
330
+ ")
331
+ ```
332
+
333
+ ### Listing defined guards/groups for the current project
334
+
335
+ You can list the defined groups and guards for the current Guardfile from the command line using `guard show` or `guard -T`:
336
+
337
+ ``` bash
338
+ # guard -T
339
+
340
+ (global):
341
+ shell
342
+ Group backend:
343
+ bundler
344
+ rspec: cli => "--color --format doc"
345
+ Group frontend:
346
+ coffeescript: output => "public/javascripts/compiled"
347
+ livereload
348
+ ```
349
+
350
+ User config file
351
+ ----------------
352
+
353
+ If a `.guard.rb` is found in your home directory, it will be appended to
354
+ the Guardfile. This can be used for tasks you want guard to handle but
355
+ other users probably don't. For example, indexing your source tree with
356
+ [Ctags](http://ctags.sourceforge.net):
357
+
358
+ ``` ruby
359
+ guard 'shell' do
360
+ watch(%r{^(?:app|lib)/.+\.rb$}) { `ctags -R` }
361
+ end
362
+ ```
363
+
364
+ Create a new guard
365
+ ------------------
366
+
367
+ Creating a new guard is very easy, just create a new gem (`bundle gem` if you use Bundler) with this basic structure:
368
+
369
+ ```
370
+ .travis.yml # bonus point!
371
+ CHANGELOG.md # bonus point!
372
+ Gemfile
373
+ guard-name.gemspec
374
+ Guardfile
375
+ lib/
376
+ guard/
377
+ guard-name/
378
+ templates/
379
+ Guardfile # needed for `guard init <guard-name>`
380
+ version.rb
381
+ guard-name.rb
382
+ test/ # or spec/
383
+ README.md
384
+ ```
385
+
386
+ `Guard::GuardName` (in `lib/guard/guard-name.rb`) must inherit from `Guard::Guard` and should overwrite at least one of the five basic `Guard::Guard` instance methods.
387
+
388
+ Here is an example scaffold for `lib/guard/guard-name.rb`:
389
+
390
+ ``` ruby
391
+ require 'guard'
392
+ require 'guard/guard'
393
+
394
+ module Guard
395
+ class GuardName < Guard
396
+
397
+ def initialize(watchers=[], options={})
398
+ super
399
+ # init stuff here, thx!
400
+ end
401
+
402
+ # =================
403
+ # = Guard methods =
404
+ # =================
405
+
406
+ # If one of those methods raise an exception, the Guard::GuardName instance
407
+ # will be removed from the active guards.
408
+
409
+ # Called once when Guard starts
410
+ # Please override initialize method to init stuff
411
+ def start
412
+ true
413
+ end
414
+
415
+ # Called on Ctrl-C signal (when Guard quits)
416
+ def stop
417
+ true
418
+ end
419
+
420
+ # Called on Ctrl-Z signal
421
+ # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
422
+ def reload
423
+ true
424
+ end
425
+
426
+ # Called on Ctrl-\ signal
427
+ # This method should be principally used for long action like running all specs/tests/...
428
+ def run_all
429
+ true
430
+ end
431
+
432
+ # Called on file(s) modifications
433
+ def run_on_change(paths)
434
+ true
435
+ end
436
+
437
+ end
438
+ end
439
+ ```
440
+
441
+ Please take a look at the [existing guards' source code](https://github.com/guard/guard/wiki/List-of-available-Guards) for more concrete example and inspiration.
442
+
443
+ Alternatively, a new guard can be added inline to a Guardfile with this basic structure:
444
+
445
+ ``` ruby
446
+ require 'guard/guard'
447
+
448
+ module ::Guard
449
+ class InlineGuard < ::Guard::Guard
450
+ def run_all
451
+ true
452
+ end
453
+
454
+ def run_on_change(paths)
455
+ true
456
+ end
457
+ end
458
+ end
459
+ ```
460
+
461
+ Here is a very cool example by [@avdi](https://github.com/avdi) : http://avdi.org/devblog/2011/06/15/a-guardfile-for-redis
462
+
463
+ Development
464
+ -----------
465
+
466
+ * Source hosted at [GitHub](https://github.com/guard/guard).
467
+ * Report issues and feature requests to [GitHub Issues](https://github.com/guard/guard/issues).
468
+
469
+ Pull requests are very welcome! Please try to follow these simple "rules", though:
470
+
471
+ - Please create a topic branch for every separate change you make;
472
+ - Make sure your patches are well tested;
473
+ - Update the README (if applicable);
474
+ - Update the CHANGELOG (maybe not for a typo but don't hesitate!);
475
+ - Please **do not change** the version number.
476
+
477
+ For questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard` (irc.freenode.net).
478
+
479
+ Author
480
+ ------
481
+
482
+ [Thibaud Guillaume-Gentil](https://github.com/thibaudgg)
483
+
484
+ Contributors
485
+ ------------
486
+
487
+ https://github.com/guard/guard/contributors