Skip to content

rnestertsov/watch

Repository files navigation

Watch - Auto-Recompile File Watcher

A lightweight file watcher that automatically triggers rebuild commands when source files change.

Features

  • 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

Installation

go install github.com/rnestertsov/watch@latest

Or build from source:

git clone https://github.com/rnestertsov/watch
cd watch
go build -o watch

Usage

Basic Usage

# 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

Command-Line Flags

--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

Language Detection

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.

Troubleshooting

Watcher not triggering on file save

Some editors use atomic save (write to temp file, then rename). This should work fine with fsnotify, but if you have issues:

  1. Try increasing debounce: --debounce 1000
  2. Check that your file matches the pattern: use --verbose to see what's being watched
  3. Verify the file isn't in an ignored directory

Too many rebuilds

Increase the debounce delay:

watch --cmd "make" --debounce 1000  # Wait 1 second

License

MIT License - see LICENSE file for details.

Acknowledgments

  • Uses fsnotify for cross-platform file watching

About

A lightweight file watcher that automatically triggers rebuild commands when source files change.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors