This is for the lazy ones: Run this in your working directory to have simple commands run on directory content change.
Watch.go:
In Golang: http://play.golang.org/p/Gtyi-z6q15
// Watch looks at current directory, if there are files changing, it runs a command.
package main
import (
"flag"
"fmt"
"io/ioutil"
"os/exec"
"strings"
"time"
)
var CheckInterval = flag.Int64("t", 2, "Interval in seconds between checks.")
func Usage() {
fmt.Println("Watch [-t <interval>] <command>")
}
func main() {
flag.Parse()
now := time.Now()
fmt.Println("From now on,", flag.Args(), "will be run on file change.")
willRun := false
for {
willRun = false
files, _ := ioutil.ReadDir(".")
for _, f := range files {
willRun = now.Before(f.ModTime())
if willRun {
fmt.Println("\nFile changed: ", f.Name())
break
}
}
if willRun {
fmt.Println("Running: ", flag.Args())
out, _ := exec.Command("/bin/bash", "-c", strings.Join(flag.Args(), " ")).CombinedOutput()
fmt.Println(string(out))
} else {
fmt.Print(".")
}
now = time.Now()
time.Sleep(time.Duration(*CheckInterval) * time.Second)
}
}