Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
F

fswatch

> 编程语言
Open source

Watch file change, and trigger commands. (Cross platform)

348 stars0 likes0 views
WebsiteGitHub

About

Watch file change, and trigger commands. (Cross platform)

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(not well tested).

Install

go install github.com/codeskyblue/fswatch@latest

Simple way to use fswatch

Usage example

$ fswatch -v
3.0
$ fswtach --help
show help message ...

Watch file change event and trigger command

TODO: now only watch *.go, *.c, *.py files, watch depth = 0 (current directory)

bash
$ fswatch sh -c "ls -l | wc -l"
fswatch >>> [] exec start: sh -c 'ls -l | wc -l'
       8
fswatch >>> [] finish in 11.822873ms
fswatch >>> changed: fswatch.go
fswatch >>> delay: 100ms
fswatch >>> [] exec start: [sh -c ls -l | wc -l]
       8
fswatch >>> [] finish in 13.606428ms
^Cfswatch >>> Catch signal interrupt!
fswatch >>> Kill all running ... Done

Hard way to use fswatch (not recommend)

Step 1

Create a config file fsw.yml

config file example though command fswatch with no arguments

yaml
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

support specify config file through fswatch --config myfsw.yml

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

reference

Other

Chinese Blog:

Friendly link:

  • bee
  • fsnotify

Code History

I reviewed the first version of fswatch(which was taged 0.1). The code I look now is shit. So I deleted almost 80% code, And left some very useful functions.

Alternative

  • write with cpp
  • Funny name.

LICENSE

Under MIT

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Go

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言