Content inside tiro
(The raw file follows this syntax highlighted file.)

package main

import (
	"flag"
	"fmt"
	"github.com/fsnotify/fsnotify"
	"os"
	"os/exec"
	"path/filepath"
	"sync"
	"time"
)

var simple = flag.Bool("simple", false, "")
var simpleDelay = flag.Int("simpleDelay", 100, "")
var maxChurnHz = flag.Int("maxChurnHz", 10, "")
var timeToSettle = flag.Int("timeToSettle", 10, "")

func modTime(s string) time.Time {
	fi, err := os.Stat(s)
	if err != nil {
		fmt.Printf("Failed to get file stat for %s: %s -- assuming file was modified right now\n", s, err)
		return time.Now()
	}
	return fi.ModTime()
}

func main() {
	flag.Parse()
	if len(flag.Args()) < 2 {
		fmt.Println(`
You must provide at least two arguments.
The first is the command to run when a change is seen.
The second, *and all remaining arguments*, are the items that will be watched - whose changes trigger the given command.
E.g.: tiro some_script.sh /some/folder some_file
`)
		os.Exit(1)
	}
	script := flag.Args()[0]
	fmt.Printf("Will run '%s' when anything changes\n", script)
	var events chan fsnotify.Event
	var errors chan error
	var churnMutex sync.Mutex
	churn := 0
	ignoreChanges := false
	go func() {
		for {
			time.Sleep(1 * time.Second)
			if churn > *maxChurnHz {
				fmt.Printf(
					"Changes are happening faster than the maxChurnHz (%d per second). "+
						"Ignoring changes for %d second(s)\n",
					*maxChurnHz,
					*timeToSettle,
				)
				ignoreChanges = true
				go func() {
					time.Sleep(time.Duration(*timeToSettle) * time.Second)
					ignoreChanges = false
				}()
			}
			churnMutex.Lock()
			churn = 0
			churnMutex.Unlock()
		}
	}()
	if *simple {
		events = make(chan fsnotify.Event)
		errors = make(chan error) // Ignored on simple flag
		watched := map[string]time.Time{}
		for _, v := range flag.Args()[1:] {
			watchPattern := filepath.Clean(v)
			fmt.Println("Checking:", watchPattern)
			matches, err := filepath.Glob(watchPattern)
			if err != nil {
				fmt.Printf("FATAL: Failed to match %q: %v", watchPattern, err)
				os.Exit(1)
			}
			for _, match := range matches {
				watched[match] = modTime(match)
			}

		}
		go func() {
			for {
				for k, v := range watched {
					newTime := modTime(k)
					if newTime != v {
						watched[k] = newTime
						events <- fsnotify.Event{k, fsnotify.Write}
					}
				}
				time.Sleep(time.Duration(*simpleDelay) * time.Millisecond)
			}
		}()
	} else {
		watcher, err := fsnotify.NewWatcher()
		if err != nil {
			fmt.Println("FATAL: Failed to create a new fsnotify watcher:", err)
			os.Exit(1)
		}
		defer watcher.Close()

		for _, v := range flag.Args()[1:] {
			err = watcher.Add(v)
			if err != nil {
				fmt.Println("FATAL: Failed to watch given argument:", v, err)
				os.Exit(1)
			}
			fmt.Println("Watching:", v)
		}
		events = watcher.Events
		errors = watcher.Errors
	}

	for {
		select {
		case <-events:
			if ignoreChanges {
				continue
			}
			churnMutex.Lock()
			churn += 1
			churnMutex.Unlock()
			fmt.Print("*")
			c := exec.Command(script)
			bs, err := c.CombinedOutput()
			if err != nil {
				fmt.Printf("\n\nERROR:\n%s\n%s\n\n", err, string(bs))
			} else {
				fmt.Printf("\n%s", string(bs))
			}
		case err := <-errors:
			fmt.Println("\n\nFATAL ERROR:", err)
			os.Exit(1)
		}
	}
}


The raw file follows...


package main

import (
	"flag"
	"fmt"
	"github.com/fsnotify/fsnotify"
	"os"
	"os/exec"
	"path/filepath"
	"sync"
	"time"
)

var simple = flag.Bool("simple", false, "")
var simpleDelay = flag.Int("simpleDelay", 100, "")
var maxChurnHz = flag.Int("maxChurnHz", 10, "")
var timeToSettle = flag.Int("timeToSettle", 10, "")

func modTime(s string) time.Time {
	fi, err := os.Stat(s)
	if err != nil {
		fmt.Printf("Failed to get file stat for %s: %s -- assuming file was modified right now\n", s, err)
		return time.Now()
	}
	return fi.ModTime()
}

func main() {
	flag.Parse()
	if len(flag.Args()) < 2 {
		fmt.Println(`
You must provide at least two arguments.
The first is the command to run when a change is seen.
The second, *and all remaining arguments*, are the items that will be watched - whose changes trigger the given command.
E.g.: tiro some_script.sh /some/folder some_file
`)
		os.Exit(1)
	}
	script := flag.Args()[0]
	fmt.Printf("Will run '%s' when anything changes\n", script)
	var events chan fsnotify.Event
	var errors chan error
	var churnMutex sync.Mutex
	churn := 0
	ignoreChanges := false
	go func() {
		for {
			time.Sleep(1 * time.Second)
			if churn > *maxChurnHz {
				fmt.Printf(
					"Changes are happening faster than the maxChurnHz (%d per second). "+
						"Ignoring changes for %d second(s)\n",
					*maxChurnHz,
					*timeToSettle,
				)
				ignoreChanges = true
				go func() {
					time.Sleep(time.Duration(*timeToSettle) * time.Second)
					ignoreChanges = false
				}()
			}
			churnMutex.Lock()
			churn = 0
			churnMutex.Unlock()
		}
	}()
	if *simple {
		events = make(chan fsnotify.Event)
		errors = make(chan error) // Ignored on simple flag
		watched := map[string]time.Time{}
		for _, v := range flag.Args()[1:] {
			watchPattern := filepath.Clean(v)
			fmt.Println("Checking:", watchPattern)
			matches, err := filepath.Glob(watchPattern)
			if err != nil {
				fmt.Printf("FATAL: Failed to match %q: %v", watchPattern, err)
				os.Exit(1)
			}
			for _, match := range matches {
				watched[match] = modTime(match)
			}

		}
		go func() {
			for {
				for k, v := range watched {
					newTime := modTime(k)
					if newTime != v {
						watched[k] = newTime
						events <- fsnotify.Event{k, fsnotify.Write}
					}
				}
				time.Sleep(time.Duration(*simpleDelay) * time.Millisecond)
			}
		}()
	} else {
		watcher, err := fsnotify.NewWatcher()
		if err != nil {
			fmt.Println("FATAL: Failed to create a new fsnotify watcher:", err)
			os.Exit(1)
		}
		defer watcher.Close()

		for _, v := range flag.Args()[1:] {
			err = watcher.Add(v)
			if err != nil {
				fmt.Println("FATAL: Failed to watch given argument:", v, err)
				os.Exit(1)
			}
			fmt.Println("Watching:", v)
		}
		events = watcher.Events
		errors = watcher.Errors
	}

	for {
		select {
		case <-events:
			if ignoreChanges {
				continue
			}
			churnMutex.Lock()
			churn += 1
			churnMutex.Unlock()
			fmt.Print("*")
			c := exec.Command(script)
			bs, err := c.CombinedOutput()
			if err != nil {
				fmt.Printf("\n\nERROR:\n%s\n%s\n\n", err, string(bs))
			} else {
				fmt.Printf("\n%s", string(bs))
			}
		case err := <-errors:
			fmt.Println("\n\nFATAL ERROR:", err)
			os.Exit(1)
		}
	}
}