guard-shell-0.7.2/0000755000004100000410000000000014052347300013755 5ustar www-datawww-dataguard-shell-0.7.2/LICENSE0000644000004100000410000000204314052347300014761 0ustar www-datawww-dataCopyright (c) 2010 Joshua Hawxwell 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. guard-shell-0.7.2/Readme.md0000644000004100000410000000426014052347300015476 0ustar www-datawww-data# Guard::Shell This little 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 Or 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, or in ruby, you can do it when a file changes with guard-shell. It simply executes the block passed to watch if a change is detected, and if anything is returned from the block it will be printed. For example ``` ruby guard :shell do watch /.*/ do |m| m[0] + " has changed." end end ``` will simply print a message telling you a file has been changed when it is changed. This admittedly isn't a very useful example, but you hopefully get the idea. To run everything on start pass `:all_on_start` to `#guard`, ``` ruby guard :shell, :all_on_start => true do # ... end ``` There is also a shortcut for easily creating notifications, ``` ruby guard :shell do watch /.*/ do |m| n m[0], 'File Changed' end end ``` `#n` takes up to three arguments; the first is the body of the message, here the path of the changed file; the second is the title for the notification; and the third is the image to use. There are three (four counting `nil` the default) different images that can be specified `:success`, `:pending` and `:failed`. ### Examples #### Saying the Name of the File You Changed and Displaying a Notification ``` ruby guard :shell do watch /(.*)/ do |m| n m[0], 'Changed' `say -v cello #{m[0]}` end end ``` #### Rebuilding LaTeX ``` ruby guard :shell, :all_on_start => true do watch /^([^\/]*)\.tex/ do |m| `pdflatex -shell-escape #{m[0]}` `rm #{m[1]}.log` count = `texcount -inc -nc -1 #{m[0]}`.split('+').first msg = "Built #{m[1]}.pdf (#{count} words)" n msg, 'LaTeX' "-> #{msg}" end end ``` #### Check Syntax of a Ruby File ``` ruby guard :shell do watch /.*\.rb$/ do |m| if system("ruby -c #{m[0]}") n "#{m[0]} is correct", 'Ruby Syntax', :success else n "#{m[0]} is incorrect", 'Ruby Syntax', :failed end end end ```guard-shell-0.7.2/lib/0000755000004100000410000000000014052347300014523 5ustar www-datawww-dataguard-shell-0.7.2/lib/guard/0000755000004100000410000000000014052347300015625 5ustar www-datawww-dataguard-shell-0.7.2/lib/guard/shell/0000755000004100000410000000000014052347300016734 5ustar www-datawww-dataguard-shell-0.7.2/lib/guard/shell/version.rb0000644000004100000410000000010314052347300020740 0ustar www-datawww-datamodule Guard module ShellVersion VERSION = '0.7.2' end end guard-shell-0.7.2/lib/guard/shell/templates/0000755000004100000410000000000014052347300020732 5ustar www-datawww-dataguard-shell-0.7.2/lib/guard/shell/templates/Guardfile0000644000004100000410000000024314052347300022556 0ustar www-datawww-data# Add files and commands to this file, like the example: # watch(%r{file/path}) { `command(s)` } # guard :shell do watch(/(.*).txt/) {|m| `tail #{m[0]}` } end guard-shell-0.7.2/lib/guard/shell.rb0000644000004100000410000000267314052347300017271 0ustar www-datawww-datarequire 'guard/compat/plugin' require 'guard/shell/version' module Guard class Shell < Plugin # Calls #run_all if the :all_on_start option is present. def start run_all if options[:all_on_start] end # Defined only to make callback(:stop_begin) and callback(:stop_end) working def stop end # Call #run_on_change for all files which match this guard. def run_all available_watchers.each do |watcher| output = watcher.call_action([]) run_on_modifications(output) end end # Print the result of the command(s), if there are results to be printed. def run_on_modifications(res) $stdout.puts res if res end def available_watchers watchers end end class Dsl # Easy method to display a notification def n(msg, title='', image=nil) Compat::UI.notify(msg, :title => title, :image => image) end # Eager prints the result for stdout and stderr as it would be written when # running the command from the terminal. This is useful for long running # tasks. def eager(command) require 'pty' begin PTY.spawn command do |r, w, pid| begin $stdout.puts r.each {|line| print line } rescue Errno::EIO # the process has finished end end rescue PTY::ChildExited $stdout.puts "The child process exited!" end end end end guard-shell-0.7.2/guard-shell.gemspec0000644000004100000410000000315114052347300017531 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: guard-shell 0.7.2 ruby lib Gem::Specification.new do |s| s.name = "guard-shell".freeze s.version = "0.7.2" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["Joshua Hawxwell".freeze, "Codru\u021B Constantin Gu\u0219oi".freeze] s.date = "2021-04-11" s.description = " Guard::Shell automatically runs shell commands when watched files are\n modified.\n".freeze s.email = "mail+rubygems@codrut.pro".freeze s.files = ["LICENSE".freeze, "Readme.md".freeze, "lib/guard/shell.rb".freeze, "lib/guard/shell/templates/Guardfile".freeze, "lib/guard/shell/version.rb".freeze] s.homepage = "http://github.com/sdwolfz/guard-shell".freeze s.licenses = ["MIT".freeze] s.rubygems_version = "2.7.6.2".freeze s.summary = "Guard gem for running shell commands".freeze if s.respond_to? :specification_version then s.specification_version = 4 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q.freeze, [">= 2.0.0"]) s.add_runtime_dependency(%q.freeze, ["~> 1.0"]) else s.add_dependency(%q.freeze, [">= 2.0.0"]) s.add_dependency(%q.freeze, ["~> 1.0"]) end else s.add_dependency(%q.freeze, [">= 2.0.0"]) s.add_dependency(%q.freeze, ["~> 1.0"]) end end