Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Guard::Shell automatically run shell commands when watched files are modified.
branch: master

This branch is 62 commits behind hawx:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib/guard
spec
.gitignore
Gemfile
Gemfile.lock
Guardfile
LICENSE
Rakefile
Readme.md
guard-shell.gemspec

Readme.md

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 installed.

Install the gem with:

gem install guard-shell

Add it to your Gemfile:

guard '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
Something went wrong with that request. Please try again.