/fswatch

fswatch is a golang developer tool that triggers commands in response to filesystem changes. Works well on Mac, Linux, and should also works on Windows.With this tool developers can create, auto compile and reload, develop, and test quickly and easily.

Primary LanguageGoMIT LicenseMIT

fswatch

fswatch is a developer tool that triggers commands in response to filesystem changes. Works well on Mac, Linux, and should also works on Windows.

Install

go get -u -v github.com/asktalk/fswatch

Quick start

Step 1

Create a config file .fsw.yml, quickly generated by the following command.

fswatch init

config file example

desc: Auto generated by fswatch [fswatch]
triggers:
- pattens:
  - '**/*.go'
  - '**/*.c'
  # also support '!**/test_*.go'
  env:
    DEBUG: "1"
  # if shell is true, $cmd will be wrapped with `bash -c`
  shell: true
  cmd: go test -v
  delay: 100ms
  stop_timeout:1s
  signal: "KILL"
  kill_signal: "SIGTERM"
watch_paths:
- .
watch_depth: 5

Step 2

Run fswatch directly. Every time you edit a file. Command go test -v will be called.

$ fswatch
fswatch >>> exec start: go test -v
# github.com/codeskyblue/fswatch
./fswatch.go:281: main redeclared in this block
	previous declaration at ./config.go:354
fswatch >>> program exited: exit status 2
fswatch >>> finish in 145.499911ms

You should know

How fswatch kill process

fswatch send signal to all process when restart. (mac and linux killed by pgid, windows by taskkill) Ctrl+C will trigger fswatch quit and kill all process it started.

Pattens

More about the pattens. The patten has the same rule like .gitignore. So you can write like this.

- pattens:
  - '*.go'
  - '!*_test.go'
  - '!**/bindata.go'

main.go changed will trigger command, but a_test.go and libs/bindata.go will be ignored.

FAQs

too many open files

For mac, run the following command

sysctl -w kern.maxfiles=20480
sysctl -w kern.maxfilesperproc=18000
ulimit -S -n 2048

Friendly link:

  • codeskyblue-fswatch, This open source project is no longer working and has been out of repair for a long time. I recreated this project and continued to maintain the project.

LICENSE

Under MIT