Skip to content

Instantly share code, notes, and snippets.

@oranj
Created October 11, 2012 15:46
Show Gist options
  • Save oranj/3873319 to your computer and use it in GitHub Desktop.
Save oranj/3873319 to your computer and use it in GitHub Desktop.
Engine to watch files
#This file lists a bunch of callbacks for file changed events.
#@ /Users/raym/Sites/myon/includes/content/js/reader/player.3.2.js
java -jar $HOME/Sites/myon/server/utils/rm/lib/yuicompressor-2.4.7.jar /Users/raym/Sites/myon/includes/content/js/reader/player.3.2.js -o /Users/raym/Sites/myon/includes/content/js/reader/player.min.3.2.js;
echo "Hello world";
#!/usr/bin/env ruby
#require 'fssm'
def starts_with(line, prefix)
prefix = prefix.to_s
line[0, prefix.length] == prefix
end
def parse_tab(filename)
out = Hash.new
watch = ""
File.open( filename).each do |line|
if starts_with(line, "#\@") then
watch = line[2, line.length].strip!
out[watch] = Array.new
elsif ! starts_with(line, '#') && line.strip! != "" && watch != "" then
out[watch].push(line)
end
end
out
end
def execute_scripts(file, scripts)
puts "\033[0;36m"+file + "\033[0m modified;"
scripts.each do |line|
`#{line}`
end
puts "\033[1;33mDone\033[0m";
end
def main(filename, sleep_interval = 4)
callbacks = parse_tab filename
callbacks_modified = Hash.new
#callbacks.each_pair do |file,scripts|
# FSSM.monitor(file) do
# update do |abs,rel|
# execute_scripts(file, scripts)
# end
# end
#end
# main loop
while true do
callbacks.each_pair do |file,scripts|
modified=`stat -f "%m" #{file}`;
if callbacks_modified[file] != modified then
callbacks_modified[file] = modified;
execute_scripts(file, scripts);
end
end
sleep sleep_interval
end
end
main "tab.sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment