watcher icon indicating copy to clipboard operation
watcher copied to clipboard

Recursive watch for file pattern

Open pellared opened this issue 5 years ago • 2 comments

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.

pellared avatar May 28 '20 17:05 pellared

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.

deividaspetraitis avatar Aug 10 '20 07:08 deividaspetraitis

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

jonny-rimek avatar Mar 20 '21 18:03 jonny-rimek