A lightweight file watcher that automatically triggers rebuild commands when source files change.
- Recursive directory watching with configurable file patterns
- Smart language detection - auto-detects Go, Rust, Node.js projects
- Debounced rebuilds - prevents redundant builds during rapid edits (500ms default)
- Real-time output streaming - integrates seamlessly with Emacs compilation mode
- Cross-platform - works on Linux, macOS, Windows via fsnotify
- Graceful shutdown - handles Ctrl+C cleanly, no zombie processes
go install github.com/rnestertsov/watch@latestOr build from source:
git clone https://github.com/rnestertsov/watch
cd watch
go build -o watch# Auto-detect project type and watch relevant files
watch --cmd "go build"
# With verbose output
watch --cmd "go build" --verbose
# Watch specific directory
watch --cmd "cargo build" --dir ./myproject
# Custom file patterns
watch --cmd "make test" --pattern "*.c" --ignore "build/"
# Multiple ignore patterns
watch --cmd "npm run build" --ignore "node_modules/,dist/,*.test.js"
# Custom debounce delay (in milliseconds)
watch --cmd "go test" --debounce 1000--cmd string Build command to run (required, e.g., "go build")
--dir string Directory to watch (default: current directory)
--pattern string File pattern to watch (default: auto-detect from project)
--ignore string Comma-separated patterns to ignore
--debounce int Milliseconds to wait after file change (default: 500)
--verbose Show watcher activity and timing info
Watch automatically detects your project type and sets appropriate defaults:
| Project Type | Detection | Pattern | Ignored Directories |
|---|---|---|---|
| Go | *.go files |
*.go |
.git/, vendor/ |
| Rust | Cargo.toml |
*.rs |
.git/, target/ |
| Node.js | package.json |
*.{js,ts,jsx,tsx} |
.git/, node_modules/, dist/ |
| Other | - | * |
.git/ |
You can override these defaults with --pattern and --ignore flags.
Some editors use atomic save (write to temp file, then rename). This should work fine with fsnotify, but if you have issues:
- Try increasing debounce:
--debounce 1000 - Check that your file matches the pattern: use
--verboseto see what's being watched - Verify the file isn't in an ignored directory
Increase the debounce delay:
watch --cmd "make" --debounce 1000 # Wait 1 secondMIT License - see LICENSE file for details.
- Uses fsnotify for cross-platform file watching