Permalink
Browse files

Initial import

  • Loading branch information...
0 parents commit bbf2c176b3db0ab9b515b11a2530d284f64d2d12 @pehlert committed Oct 27, 2012
Showing with 118 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +20 −0 LICENSE
  3. +38 −0 Readme.md
  4. +21 −0 guard-addremove.gemspec
  5. +32 −0 lib/guard/addremove.rb
  6. +6 −0 lib/guard/addremove/templates/Guardfile
@@ -0,0 +1 @@
+*.gem
@@ -0,0 +1,20 @@
+Copyright (c) 2012 Pascal Ehlert
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
+# Guard::Addremove
+
+This guard allows you execute shell commands whenever files are added or removed.
+It is very much like guard-shell, but ignores changes to existing files.
+
+
+## Install
+
+Make sure you have [guard](http://github.com/guard/guard) installed.
+
+Install the gem with:
+
+ gem install guard-addremove
+
+Or add it to your Gemfile:
+
+ gem 'guard-addremove'
+
+And then add a basic setup to your Guardfile:
+
+ guard init addremove
+
+
+## Usage
+
+This guard was originally written to allow the removal of caches when the filesystem changes.
+This can be helpful in combination with vim's plugins CtrlP or Command-T. Find a quick guide how
+to use it in my [blog](http://www.hacksrus.net/blog/2012/10/using-vims-ctrlp/).
+
+``` ruby
+guard :addremove do
+ watch /.*/ do |m|
+ `echo "#{m[0]} has been added or removed."`
+ end
+end
+```
+
+will simply print a message telling you a file has been added or removed.
@@ -0,0 +1,21 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path("../lib/guard/addremove", __FILE__)
+
+Gem::Specification.new do |s|
+ s.name = "guard-addremove"
+ s.author = "Pascal Ehlert"
+ s.email = "pascal@hacksrus.net"
+ s.summary = "Guard gem for running shell commands when files are added or removed"
+ s.homepage = "http://github.com/pehlert/guard-addremove"
+ s.version = Guard::Addremove::VERSION
+
+ s.description = <<-DESC
+ Guard::Addremove automatically runs shell commands when watched files are added or
+ removed from the file system.
+ DESC
+
+ s.add_dependency 'guard', '>= 0.2.0'
+
+ s.files = %w(Readme.md LICENSE)
+ s.files += Dir["{lib}/**/*"]
+end
@@ -0,0 +1,32 @@
+require 'guard'
+require 'guard/guard'
+require 'guard/watcher'
+
+module Guard
+ class Addremove < Guard
+
+ VERSION = '1.0.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_additions for all files which match this guard.
+ def run_all
+ run_on_additions(Watcher.match_files(self, Dir.glob('{,**/}*{,.*}').uniq))
+ end
+
+ def run_on_additions(res)
+ puts res if res
+ end
+ alias_method :run_on_removals, :run_on_additions
+ end
+
+ class Dsl
+ # Taken from guard-shell. Easy method to display a notification
+ def n(msg, title='', image=nil)
+ Notifier.notify(msg, :title => title, :image => image)
+ end
+ end
+end
@@ -0,0 +1,6 @@
+# Add files and commands to this file, like the example:
+# watch(%r{file/path}) { `command(s)` }
+#
+guard 'addremove' do
+ watch(/(.*)/) {|m| `echo "File as been added or removed: #{m[0]}"` }
+end

0 comments on commit bbf2c17

Please sign in to comment.