Last active
December 16, 2016 14:36
-
-
Save Deradon/4709541 to your computer and use it in GitHub Desktop.
Re-run a command whenever a file in directory is changed!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Re-run a command whenever a file in directory is changed! | |
# | |
# Inspired by: http://ngauthier.com/2012/02/quick-tests-with-bash.html | |
# Thanks Nick! | |
# | |
# Patrick Helm (me@patrick-helm.de), 2013 | |
# | |
# | |
# Requirements: sudo apt-get install inotify-tools | |
# | |
# Usage: "live command" | |
# | |
# Example: | |
# > live rspec spec | |
# > live rake test | |
# | |
# .live | |
# * Create a file named '.live' and specify which files/directories to watch | |
# * <filename> to watch | |
# * @<filename> to ignore | |
# | |
# Example .live: | |
# app/ | |
# lib/ | |
# spec/ | |
# Just join args | |
args = ARGV.join(" ") | |
# Prepare the live command | |
puts "Reading from .live" if File.exists?(".live") | |
cmd = File.exists?(".live") ? "--fromfile .live" : "*" | |
cmd = "#{args}; while true; do inotifywait --exclude '.*\.swp' -r -e modify #{cmd}; #{args}; done" | |
puts "$: #{cmd}" | |
# Run the 'live' command | |
exec(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment