-
-
Save anthonybishopric/9644828 to your computer and use it in GitHub Desktop.
gat: execute the given command every time the working dir changes
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 | |
# | |
# Example usage: | |
# | |
# 1> $ cd github.com/anthonybishopric/gotcha | |
# 1> $ gat go test # begin listening to this directory | |
# | |
# 2> $ cd github.com/anthonybishopric/gotcha | |
# 2> $ touch README.md | |
# PASS | |
# ok github.com/anthonybishopric/gotcha 0.016s | |
require 'rb-fsevent' | |
require 'optparse' | |
options = {} | |
opts = OptionParser.new do |opts| | |
opts.banner = "Run a command when contents in this directory change.\nUsage: gat [-n|--no-clear] <command>" | |
opts.on("-n", "--[no-]clear", "Don't clear the screen before execution") do |n| | |
options[:no_clear] = n | |
end | |
opts.on_tail("-h", "--help", "Show help") do | |
puts opts | |
exit | |
end | |
end | |
opts.parse! | |
command = ARGV.join(" ") | |
if command == "" | |
puts opts | |
exit 1 | |
end | |
unless options[:no_clear] | |
command = "clear && #{command}" | |
end | |
fsevent = FSEvent.new | |
fsevent.watch Dir.pwd do |directories| | |
system command | |
end | |
fsevent.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment