guard-shell 0.3.0 → 0.4.0
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.
- data/Readme.md +70 -29
- data/lib/guard/shell.rb +3 -3
- metadata +4 -4
data/Readme.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Guard::Shell
|
2
2
|
|
3
|
-
This little
|
4
|
-
altered.
|
3
|
+
This little guard allows you to run shell commands when files are altered.
|
5
4
|
|
6
5
|
|
7
6
|
## Install
|
@@ -23,41 +22,83 @@ And then add a basic setup to your Guardfile:
|
|
23
22
|
|
24
23
|
## Usage
|
25
24
|
|
26
|
-
If you can do something in your shell,
|
27
|
-
guard-shell. It
|
28
|
-
|
25
|
+
If you can do something in your shell, or in ruby, you can do it when a file changes
|
26
|
+
with guard-shell. It simply executes the block passed to watch if a change is
|
27
|
+
detected, and if anything is returned from the block it will be printed. For example
|
29
28
|
|
30
|
-
|
31
|
-
|
29
|
+
``` ruby
|
30
|
+
guard :shell do
|
31
|
+
watch /.*/ do |m|
|
32
|
+
m[0] + " has changed."
|
33
|
+
end
|
34
|
+
end
|
35
|
+
```
|
32
36
|
|
33
|
-
|
37
|
+
will simply print a message telling you a file has been changed when it is changed.
|
38
|
+
This admittedly isn't a very useful example, but you hopefully get the idea. To run
|
39
|
+
everything on start pass `:all_on_start` to `#guard`,
|
34
40
|
|
35
|
-
|
41
|
+
``` ruby
|
42
|
+
guard :shell, :all_on_start => true do
|
43
|
+
# ...
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
There is also a shortcut for easily creating notifications,
|
48
|
+
|
49
|
+
``` ruby
|
50
|
+
guard :shell do
|
51
|
+
watch /.*/ do |m|
|
52
|
+
n m[0], 'File Changed'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
`#n` takes up to three arguments; the first is the body of the message, here the path
|
58
|
+
of the changed file; the second is the title for the notification; and the third is
|
59
|
+
the image to use. There are three (four counting `nil` the default) different images
|
60
|
+
that can be specified `:success`, `:pending` and `:failed`.
|
36
61
|
|
37
|
-
|
38
|
-
|
39
|
-
watch(/(.*)/) {|m| m[0] + " was just changed" }
|
40
|
-
end
|
62
|
+
|
63
|
+
### Examples
|
41
64
|
|
42
65
|
#### Saying the Name of the File You Changed and Displaying a Notification
|
43
66
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
67
|
+
``` ruby
|
68
|
+
guard :shell do
|
69
|
+
watch /(.*)/ do |m|
|
70
|
+
n m[0], 'Changed'
|
71
|
+
`say -v cello #{m[0]}`
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
50
75
|
|
51
76
|
#### Rebuilding LaTeX
|
52
77
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
78
|
+
``` ruby
|
79
|
+
guard :shell, :all_on_start => true do
|
80
|
+
watch /^([^\/]*)\.tex/ do |m|
|
81
|
+
`pdflatex -shell-escape #{m[0]}`
|
82
|
+
`rm #{m[1]}.log`
|
83
|
+
|
84
|
+
count = `texcount -inc -nc -1 #{m[0]}`.split('+').first
|
85
|
+
msg = "Built #{m[1]}.pdf (#{count} words)"
|
86
|
+
n msg, 'LaTeX'
|
87
|
+
"-> #{msg}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
#### Check Syntax of a Ruby File
|
93
|
+
|
94
|
+
``` ruby
|
95
|
+
guard :shell do
|
96
|
+
watch /.*\.rb$/ do |m|
|
97
|
+
if system('ruby -c #{m[0]}')
|
98
|
+
n "#{m[0]} is correct", 'Ruby Syntax', :success
|
99
|
+
else
|
100
|
+
n "#{m[0]} is incorrect", 'Ruby Syntax', :failed
|
63
101
|
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
```
|
data/lib/guard/shell.rb
CHANGED
@@ -5,7 +5,7 @@ require 'guard/watcher'
|
|
5
5
|
module Guard
|
6
6
|
class Shell < Guard
|
7
7
|
|
8
|
-
VERSION = '0.
|
8
|
+
VERSION = '0.4.0'
|
9
9
|
|
10
10
|
# Calls #run_all if the :all_on_start option is present.
|
11
11
|
def start
|
@@ -26,8 +26,8 @@ module Guard
|
|
26
26
|
|
27
27
|
class Dsl
|
28
28
|
# Easy method to display a notification
|
29
|
-
def n(msg, title='')
|
30
|
-
|
29
|
+
def n(msg, title='', image=nil)
|
30
|
+
Notifier.notify(msg, :title => title, :image => image)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-shell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: guard
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156563560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 0.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156563560
|
25
25
|
description: ! " Guard::Shell automatically runs shell commands when watched files
|
26
26
|
are\n modified.\n"
|
27
27
|
email: m@hawx.me
|