guard-shell 0.1.1 → 0.2.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 CHANGED
@@ -12,9 +12,9 @@ Install the gem with:
12
12
 
13
13
  gem install guard-shell
14
14
 
15
- Add it to your Gemfile:
15
+ Or add it to your Gemfile:
16
16
 
17
- guard 'guard-shell'
17
+ gem 'guard-shell'
18
18
 
19
19
  And then add a basic setup to your Guardfile:
20
20
 
@@ -23,37 +23,42 @@ And then add a basic setup to your Guardfile:
23
23
 
24
24
  ## Usage
25
25
 
26
- If you can do something in your shell, it is probably very easy to setup with guard-shell, here are a few examples.
26
+ If you can do something in your shell, it is probably very easy to setup with
27
+ guard-shell. It can take an option, `:all_on_start` which will, if set to true,
28
+ run all tasks on start.
27
29
 
30
+ There is also a shortcut method, `#n(msg, title='')`, which can be used to
31
+ display a notification within your watch blocks. See the examples for usage.
28
32
 
29
- #### Creating Backups of Files On Change
30
-
31
- guard 'shell' do
32
- # create a copy of the file with '.backup' at the end
33
- watch('(.*)') {|m| `cp #{m[0]} #{m[0]}.backup` }
34
- end
33
+ ### Examples
35
34
 
35
+ #### Printing the Name of the File You Changed
36
36
 
37
- #### Showing git st
38
-
39
- guard 'shell' do
40
- watch('.*') { `git st` }
37
+ guard :shell do
38
+ # if the block returns something, it will be passed to `#puts`
39
+ watch(/(.*)/) {|m| m[0] + " was just changed" }
41
40
  end
42
41
 
42
+ #### Saying the Name of the File You Changed and Displaying a Notification
43
43
 
44
- #### Rebuilding a LaTeX File
45
-
46
- guard 'shell' do
47
- # builds latex file to pdf and hides output
48
- watch('(.*).tex') do |m|
49
- `pdflatex -shell-escape #{m[0]} 1>/dev/null`
50
- puts "built #{m[1]}.pdf"
44
+ guard :shell do
45
+ watch /(.*)/ do |m|
46
+ n m[0], 'Changed'
47
+ `say -v cello #{m[0]}`
51
48
  end
52
49
  end
53
50
 
54
-
55
- #### Saying the Name of the File You Changed
56
-
57
- guard 'shell' do
58
- watch('(.*)') {|m| `say #{m[0]}` }
51
+ #### Rebuilding LaTeX
52
+
53
+ guard :shell do
54
+ watch /^([^\/]*)\.tex/ do |m|
55
+ `pdflatex -shell-escape #{m[0]}`
56
+ `rm #{m[1]}.log`
57
+
58
+ count = `texcount -inc -nc -1 somehting.tex`.split('+').first
59
+ msg = "built #{m[1]}.pdf (#{count} words)"
60
+ n msg, 'LaTeX'
61
+ "-> built #{msg}"
62
+ end
59
63
  end
64
+
data/lib/guard/shell.rb CHANGED
@@ -1,19 +1,33 @@
1
1
  require 'guard'
2
2
  require 'guard/guard'
3
+ require 'guard/watcher'
3
4
 
4
5
  module Guard
5
6
  class Shell < Guard
6
7
 
7
- VERSION = '0.1.1'
8
+ VERSION = '0.2.0'
9
+
10
+ # Calls #run_all if the :all_on_start option is present.
11
+ def start
12
+ run_all if options[:all_on_start]
13
+ end
14
+
15
+ # Call #run_on_change for all files which match this guard.
16
+ def run_all
17
+ run_on_change(Watcher.match_files(self, Dir.glob('{,**/}*{,.*}').uniq))
18
+ end
8
19
 
9
- # Print the result of the command, if there is a result
10
- # to be printed. (see README.md)
11
- #
12
- # @param res [Array] the result of the commands that have run
13
- #
20
+ # Print the result of the command, if there is a result to be printed.
14
21
  def run_on_change(res)
15
22
  puts res[0] if res[0]
16
23
  end
17
-
24
+
25
+ end
26
+
27
+ class Dsl
28
+ # Easy method to display a notification
29
+ def n(msg, title='')
30
+ ::Guard::Notifier.notify(msg, :title => title)
31
+ end
18
32
  end
19
33
  end
@@ -1,6 +1,6 @@
1
1
  # Add files and commands to this file, like the example:
2
- # watch('file/path') { `command(s)` }
2
+ # watch(%r{file/path}) { `command(s)` }
3
3
  #
4
4
  guard 'shell' do
5
- watch('(.*).txt') {|m| `tail #{m[0]}` }
5
+ watch(/(.*).txt/) {|m| `tail #{m[0]}` }
6
6
  end
metadata CHANGED
@@ -1,115 +1,61 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: guard-shell
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Joshua Hawxwell
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-10-27 00:00:00 +01:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-12-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: guard
22
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2153222000 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 2
30
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
31
21
  version: 0.2.0
32
22
  type: :runtime
33
23
  prerelease: false
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: bundler
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ~>
41
- - !ruby/object:Gem::Version
42
- segments:
43
- - 1
44
- - 0
45
- - 2
46
- version: 1.0.2
47
- type: :development
48
- prerelease: false
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: rspec
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ~>
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 2
59
- - 0
60
- - 0
61
- - rc
62
- version: 2.0.0.rc
63
- type: :development
64
- prerelease: false
65
- version_requirements: *id003
66
- description: Guard::Shell automatically runs shell commands when watched files are modified.
67
- email:
68
- - m@hawx.me
24
+ version_requirements: *2153222000
25
+ description: ! " Guard::Shell automatically runs shell commands when watched files
26
+ are \n modified.\n"
27
+ email: m@hawx.me
69
28
  executables: []
70
-
71
29
  extensions: []
72
-
73
30
  extra_rdoc_files: []
74
-
75
- files:
31
+ files:
32
+ - README.md
33
+ - LICENSE
76
34
  - lib/guard/shell/templates/Guardfile
77
35
  - lib/guard/shell.rb
78
- - LICENSE
79
- - README.md
80
- has_rdoc: true
81
- homepage: http://rubygems.org/gems/guard-shell
36
+ homepage: http://github.com/hawx/guard-shell
82
37
  licenses: []
83
-
84
38
  post_install_message:
85
39
  rdoc_options: []
86
-
87
- require_paths:
40
+ require_paths:
88
41
  - lib
89
- required_ruby_version: !ruby/object:Gem::Requirement
42
+ required_ruby_version: !ruby/object:Gem::Requirement
90
43
  none: false
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- segments:
95
- - 0
96
- version: "0"
97
- required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
49
  none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- segments:
103
- - 1
104
- - 3
105
- - 6
106
- version: 1.3.6
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
107
54
  requirements: []
108
-
109
- rubyforge_project: guard-shell
110
- rubygems_version: 1.3.7
55
+ rubyforge_project:
56
+ rubygems_version: 1.8.11
111
57
  signing_key:
112
58
  specification_version: 3
113
59
  summary: Guard gem for running shell commands
114
60
  test_files: []
115
-
61
+ has_rdoc: