watcher
watcher copied to clipboard
Recursive watch for file pattern
Hello,
I wanted to use the watcher to run make when a go file is modified.
Here is how I thought it would/should work:
watcher -cmd="make all" *.go
However it works only for current directory. It does not watch for changes that are in packages. Sample file structure:
.
├── c
│ └── g.go
├── foo.go
├── foo_test.go
├── go.mod
├── go.sum
├── Makefile
Test:
$:~/repos/seed$ watcher -list -cmd="make all" *.go
/home/rpajak/repos/seed/foo.go: foo.go
/home/rpajak/repos/seed/foo_test.go: foo_test.go
Watching 2 files
Notice that c/g.go is not being watched.
One possible approach could be forming a list of *.go files to be fed to watcher, like following:
watcher -dotfiles=false -startcmd=true -cmd=watcher.sh $(find ../../ -type f -name \"*.go\" -exec echo {} \+)
However it has one downside however, to include newly created files you will need restart this process, which can be automated as well I believe.
I'm using the following cmd
watcher -cmd="./build.sh" -pipe=true $(find $directory -type f -name "*.go" -not -path "./cdk.out/*" | tr '\n' ' ')
It will watch all go files in all subdirectories from your current dir