From d6c8efa547bea3df75ff74082ba87c843298e6d9 Mon Sep 17 00:00:00 2001 From: Benjamin Radovsky Date: Wed, 12 Dec 2018 17:14:13 +1100 Subject: [PATCH] Add flag of comma separated paths to ignore. --- cmd/watcher/main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmd/watcher/main.go b/cmd/watcher/main.go index 6302b8a..60e2827 100644 --- a/cmd/watcher/main.go +++ b/cmd/watcher/main.go @@ -23,6 +23,7 @@ func main() { listFiles := flag.Bool("list", false, "list watched files on start") stdinPipe := flag.Bool("pipe", false, "pipe event's info to command's stdin") keepalive := flag.Bool("keepalive", false, "keep alive when a cmd returns code != 0") + ignore := flag.String("ignore", "", "comma separated list of paths to ignore") flag.Parse() @@ -52,6 +53,21 @@ func main() { w := watcher.New() w.IgnoreHiddenFiles(!*dotfiles) + // Get any of the paths to ignore. + ignoredPaths := strings.Split(*ignore, ",") + + for _, path := range ignoredPaths { + trimmed := strings.TrimSpace(path) + if trimmed == "" { + continue + } + + err := w.Ignore(trimmed) + if err != nil { + log.Fatalln(err) + } + } + done := make(chan struct{}) go func() { defer close(done)