Skip to content
Browse files

Merge remote-tracking branch 'hawx/master'

  • Loading branch information...
2 parents 1b93320 + 8aa1de5 commit 4816fb447379a494fe403b6adc1c217a73e7ddc6 @rtlong rtlong committed Jan 17, 2012
Showing with 67 additions and 216 deletions.
  1. +0 −3 Gemfile
  2. +0 −40 Gemfile.lock
  3. +0 −5 Guardfile
  4. +0 −59 README.md
  5. +0 −34 Rakefile
  6. +30 −26 Readme.md
  7. +14 −18 guard-shell.gemspec
  8. +21 −7 lib/guard/shell.rb
  9. +2 −2 lib/guard/shell/templates/Guardfile
  10. +0 −8 spec/guard/shell_spec.rb
  11. +0 −14 spec/spec_helper.rb
View
3 Gemfile
@@ -1,3 +0,0 @@
-source "http://rubygems.org"
-
-gemspec
View
40 Gemfile.lock
@@ -1,40 +0,0 @@
-PATH
- remote: .
- specs:
- guard-shell (0.1.1)
- guard (>= 0.2.0)
-
-GEM
- remote: http://rubygems.org/
- specs:
- configuration (1.1.0)
- diff-lcs (1.1.2)
- guard (0.2.2)
- open_gem (~> 1.4.2)
- thor (~> 0.14.3)
- launchy (0.3.7)
- configuration (>= 0.0.5)
- rake (>= 0.8.1)
- open_gem (1.4.2)
- launchy (~> 0.3.5)
- rake (0.8.7)
- rspec (2.0.1)
- rspec-core (~> 2.0.1)
- rspec-expectations (~> 2.0.1)
- rspec-mocks (~> 2.0.1)
- rspec-core (2.0.1)
- rspec-expectations (2.0.1)
- diff-lcs (>= 1.1.2)
- rspec-mocks (2.0.1)
- rspec-core (~> 2.0.1)
- rspec-expectations (~> 2.0.1)
- thor (0.14.3)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- bundler (~> 1.0.2)
- guard (>= 0.2.0)
- guard-shell!
- rspec (~> 2.0.0.rc)
View
5 Guardfile
@@ -1,5 +0,0 @@
-guard 'rspec', :version => 2 do
- watch('^spec/(.*)_spec.rb')
- watch('^lib/(.*).rb') { |m| "spec/#{m[1]}_spec.rb" }
- watch('^spec/spec_helper.rb') { "spec" }
-end
View
59 README.md
@@ -1,59 +0,0 @@
-# Guard-Shell
-
-This little addition (1 proper line of code!) to guard allows you to run shell
-commands when certain files are altered.
-
-
-## Install
-
-Make sure you have [guard](http://github.com/guard/guard) installed.
-
-Install the gem with:
-
- gem install guard-shell
-
-Add it to your Gemfile:
-
- gem 'guard-shell'
-
-And then add a basic setup to your Guardfile:
-
- guard init shell
-
-
-## Usage
-
-If you can do something in your shell, it is probably very easy to setup with guard-shell, here are a few examples.
-
-
-#### Creating Backups of Files On Change
-
- guard 'shell' do
- # create a copy of the file with '.backup' at the end
- watch('(.*)') {|m| `cp #{m[0]} #{m[0]}.backup` }
- end
-
-
-#### Showing git st
-
- guard 'shell' do
- watch('.*') { `git st` }
- end
-
-
-#### Rebuilding a LaTeX File
-
- guard 'shell' do
- # builds latex file to pdf and hides output
- watch('(.*).tex') do |m|
- `pdflatex -shell-escape #{m[0]} 1>/dev/null`
- puts "built #{m[1]}.pdf"
- end
- end
-
-
-#### Saying the Name of the File You Changed
-
- guard 'shell' do
- watch('(.*)') {|m| `say #{m[0]}` }
- end
View
34 Rakefile
@@ -1,34 +0,0 @@
-require 'bundler'
-Bundler::GemHelper.install_tasks
-
-require 'rspec/core/rake_task'
-RSpec::Core::RakeTask.new(:spec)
-task :default => :spec
-
-namespace(:spec) do
- desc "Run all specs on multiple ruby versions (requires rvm)"
- task(:portability) do
- %w[1.8.7 1.9.2].each do |version|
- system <<-BASH
- bash -c 'source ~/.rvm/scripts/rvm;
- rvm #{version};
- echo "--------- version #{version} ----------\n";
- bundle install;
- rake spec:prepare_fixtures
- rake spec'
- BASH
- end
- end
-
- desc "Run bundle install on each fixtures directories with Gemfile"
- task(:prepare_fixtures) do
- Dir.foreach("spec/fixtures") do |dir|
- if File.exists?("spec/fixtures/#{dir}/Gemfile")
- system <<-BASH
- cd spec/fixtures/#{dir};
- bundle install
- BASH
- end
- end
- end
-end
View
56 Readme.md
@@ -1,18 +1,18 @@
-# Guard-Shell
+# Guard::Shell
-This little addition (1 proper line of code!) to guard allows you to run shell
-commands when certain files are altered.
+This little addition to guard allows you to run shell commands when files are
+altered.
## Install
-
+
Make sure you have [guard](http://github.com/guard/guard) installed.
Install the gem with:
gem install guard-shell
-Add it to your Gemfile:
+Or add it to your Gemfile:
gem 'guard-shell'
@@ -23,37 +23,41 @@ And then add a basic setup to your Guardfile:
## Usage
-If you can do something in your shell, it is probably very easy to setup with guard-shell, here are a few examples.
-
-
-#### Creating Backups of Files On Change
+If you can do something in your shell, it is probably very easy to setup with
+guard-shell. It can take an option, `:all_on_start` which will, if set to true,
+run all tasks on start.
- guard 'shell' do
- # create a copy of the file with '.backup' at the end
- watch('(.*)') {|m| `cp #{m[0]} #{m[0]}.backup` }
- end
+There is also a shortcut method, `#n(msg, title='')`, which can be used to
+display a notification within your watch blocks. See the examples for usage.
+### Examples
-#### Showing git st
+#### Printing the Name of the File You Changed
- guard 'shell' do
- watch('.*') { `git st` }
+ guard :shell do
+ # if the block returns something, it will be printed with `puts`
+ watch(/(.*)/) {|m| m[0] + " was just changed" }
end
+#### Saying the Name of the File You Changed and Displaying a Notification
-#### Rebuilding a LaTeX File
-
- guard 'shell' do
- # builds latex file to pdf and hides output
- watch('(.*).tex') do |m|
- `pdflatex -shell-escape #{m[0]} 1>/dev/null`
- puts "built #{m[1]}.pdf"
+ guard :shell do
+ watch /(.*)/ do |m|
+ n m[0], 'Changed'
+ `say -v cello #{m[0]}`
end
end
+#### Rebuilding LaTeX
-#### Saying the Name of the File You Changed
+ guard :shell do
+ watch /^([^\/]*)\.tex/ do |m|
+ `pdflatex -shell-escape #{m[0]}`
+ `rm #{m[1]}.log`
- guard 'shell' do
- watch('(.*)') {|m| `say #{m[0]}` }
+ count = `texcount -inc -nc -1 #{m[0]}`.split('+').first
+ msg = "Built #{m[1]}.pdf (#{count} words)"
+ n msg, 'LaTeX'
+ "-> #{msg}"
+ end
end
View
32 guard-shell.gemspec
@@ -1,25 +1,21 @@
# -*- encoding: utf-8 -*-
-$:.push File.expand_path('../lib', __FILE__)
-require 'guard/shell'
+require File.expand_path("../lib/guard/shell", __FILE__)
Gem::Specification.new do |s|
- s.name = 'guard-shell'
- s.version = Guard::Shell::VERSION
- s.platform = Gem::Platform::RUBY
- s.authors = ['Joshua Hawxwell']
- s.email = ['m@hawx.me']
- s.homepage = 'http://rubygems.org/gems/guard-shell'
- s.summary = 'Guard gem for running shell commands'
- s.description = 'Guard::Shell automatically runs shell commands when watched files are modified.'
+ s.name = "guard-shell"
+ s.author = "Joshua Hawxwell"
+ s.email = "m@hawx.me"
+ s.summary = "Guard gem for running shell commands"
+ s.homepage = "http://github.com/hawx/guard-shell"
+ s.version = Guard::Shell::VERSION
- s.required_rubygems_version = '>= 1.3.6'
- s.rubyforge_project = 'guard-shell'
+ s.description = <<-DESC
+ Guard::Shell automatically runs shell commands when watched files are
+ modified.
+ DESC
- s.add_dependency 'guard', '>= 0.2.0'
+ s.add_dependency 'guard', '>= 0.2.0'
- s.add_development_dependency 'bundler', '~> 1.0.2'
- s.add_development_dependency 'rspec', '~> 2.0.0.rc'
-
- s.files = Dir.glob('{lib}/**/*') + %w[LICENSE README.md]
- s.require_path = 'lib'
+ s.files = %w(README.md LICENSE)
+ s.files += Dir["{lib}/**/*"]
end
View
28 lib/guard/shell.rb
@@ -1,19 +1,33 @@
require 'guard'
require 'guard/guard'
+require 'guard/watcher'
module Guard
class Shell < Guard
- VERSION = '0.1.1'
+ VERSION = '0.2.0'
+
+ # Calls #run_all if the :all_on_start option is present.
+ def start
+ run_all if options[:all_on_start]
+ end
+
+ # Call #run_on_change for all files which match this guard.
+ def run_all
+ run_on_change(Watcher.match_files(self, Dir.glob('{,**/}*{,.*}').uniq))
+ end
- # Print the result of the command, if there is a result
- # to be printed. (see README.md)
- #
- # @param res [Array] the result of the commands that have run
- #
+ # Print the result of the command, if there is a result to be printed.
def run_on_change(res)
puts res[0] if res[0]
end
-
+
+ end
+
+ class Dsl
+ # Easy method to display a notification
+ def n(msg, title='')
+ ::Guard::Notifier.notify(msg, :title => title)
+ end
end
end
View
4 lib/guard/shell/templates/Guardfile
@@ -1,6 +1,6 @@
# Add files and commands to this file, like the example:
-# watch('file/path') { `command(s)` }
+# watch(%r{file/path}) { `command(s)` }
#
guard 'shell' do
- watch('(.*).txt') {|m| `tail #{m[0]}` }
+ watch(/(.*).txt/) {|m| `tail #{m[0]}` }
end
View
8 spec/guard/shell_spec.rb
@@ -1,8 +0,0 @@
-require 'spec_helper'
-
-describe Guard::Shell do
- subject { Guard::Shell.new }
-
-
-end
-
View
14 spec/spec_helper.rb
@@ -1,14 +0,0 @@
-require 'rspec'
-require 'guard/shell'
-
-RSpec.configure do |config|
- config.color_enabled = true
- config.filter_run :focus => true
- config.run_all_when_everything_filtered = true
-
- config.before(:each) do
- ENV["GUARD_ENV"] = 'test'
- @fixture_path = Pathname.new(File.expand_path('../fixtures/', __FILE__))
- @lib_path = Pathname.new(File.expand_path('../../lib/', __FILE__))
- end
-end

0 comments on commit 4816fb4

Please sign in to comment.
Something went wrong with that request. Please try again.