From 349936a9b4aede6ba5f0c5b3c89c7331b1843bc9 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Fri, 12 Jun 2020 22:03:46 +0000 Subject: [PATCH] minor cleanup --- .gitignore | 2 ++ go.mod | 7 +++++++ go.sum | 4 ++++ main.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.gitignore b/.gitignore index 9a3a8d8..78b0489 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +bustle +*.swp # ---> Go # Binaries for programs and plugins *.exe diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6bbb057 --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module git.tilde.town/tildetown/bustle + +go 1.14 + +require ( + github.com/fsnotify/fsnotify v1.4.9 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b12c1ed --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9 h1:L2auWcuQIvxz9xSEqzESnV/QN/gNRXNApHi3fYwl2w0= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/main.go b/main.go new file mode 100644 index 0000000..126b367 --- /dev/null +++ b/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "fmt" + "log" + "os" + + "github.com/fsnotify/fsnotify" +) + +func main() { + watcher, err := fsnotify.NewWatcher() + if err != nil { + log.Fatal(err) + } + defer watcher.Close() + + done := make(chan bool) + go func() { + for { + select { + case event, ok := <-watcher.Events: + if !ok { + return + } + log.Println("event:", event) + if event.Op&fsnotify.Write == fsnotify.Write { + log.Println("modified file:", event.Name) + } + case err, ok := <-watcher.Errors: + if !ok { + return + } + log.Println("error:", err) + } + } + }() + + // will need to recursively watch for myself, including adding watchers for new directories D: + + // check out filepath.Walk + + for _, path := range os.Args[1:] { + err = watcher.Add(path) + if err != nil { + log.Fatal(err) + } + + } + <-done + + fmt.Println("hmm") +}