Watch directories and run commands automatically when files change.
- Watch multiple directories simultaneously
- Filter by file extension
- Debounced change detection (configurable)
- TOML configurable file or pure CLI mode
- Graceful shutdown on
Ctrl+C - Built-in rust for performance and reliability
git clone https://github.com/mg4603/watchr.git
cd watchr
cargo build --release
# Binary will be at target/release/watchrcargo install --path .Create a .watchr.toml in your project:
watchr initEdit .watchr.toml:
debounce_ms = 500
[[watcher]]
name = "tests"
dirs = ["src/", "tests/"]
ext = ["rs"]
command = "cargo test"
[[watcher]]
name = "lint"
dirs = ["src/"]
command = "cargo clippy"Start watching:
watchr watchWatch without a config file:
watchr watch src/ --cmd "cargo test"Watch with extension filter:
watchr watch src/ --ext rs,toml --cmd "cargo test".watchr.toml supports the following structure:
# Global debounce time in milliseconds (default: 500)
debounce_ms = 500
# Watcher entries (can define multiple)
[[watcher]]
name = "entry-name" # Optional: descriptive name
dirs = ["src/", "tests/"] # Required: directories to watch
ext = ["rs", "toml"] # Optional: file extensions (omit to watch all)
command = "cargo test" # Required: command to run on changeswatchr seraches for .watchr.toml by walking up the directory
tree from the current working directory.
Override with explicit path:
watchr watch --config /path/to/.watch.tomlGenerate a .watchr.toml template in the current directory.
watchr initErrors if .watchr.toml already exists.
Starts watching for file chagnes.
Flags:
-
--config <PATH>- Explicit path to config file -
--dir <DIR>- Directory to watch (CLI mode, requires --cmd) -
--cmd <COMMAND>- Command to run on changes (CLI mode, requires --dir) -
--ext <EXTENSIONS>- Comma-separated list of extensions to filter (CLI mode)
Examples:
# Use .watchr.toml from current directory or parent
watchr watch
# Use specific config file
watchr watch --config ~/my-project/.watchr.toml
# CLI mode: watch src/, run tests
watchr watch --dir src/ --cmd "cargo test"
# CLI mode: watch src/, filter .rs and .toml files
watchr watch --dir src/ --cmd "cargo test" --ext rs,toml[[watcher]]
name = "tests"
dirs = ["src/", "tests/"]
ext = ["rs"]
command = "cargo test"[[watcher]]
name = "build"
dirs = ["src/"]
ext = ["rs"]
command = "cargo build"[[watcher]]
name = "lint"
dirs = ["src/"]
ext = ["rs"]
command = "cargo clippy && cargo fmt"debounce_ms = 300
[[watcher]]
name = "backend"
dirs = ["backend/src/"]
ext = ["rs"]
command = "cargo test --manifest-path backend/Cargo.toml"
[[watcher]]
name = "frontend"
dirs = ["frontend/src/"]
ext = ["js", "jsx"]
command = "npm test --prefix frontend"-
File Watching: Uses
notify-debouncer-fullfor efficient filesystem monitoring -
Deboucing : Groups rapid file changes within the debounce window
-
Filtering : Check file extensions (if specified) before running commands
-
Execution : Runs commands via
sh -c "command"to support shell syntax -
Shutdown : Catches
Ctrl+Cfor graceful cleanup
-
Directory not found : Validates all directories exist before starting
-
Config errors : Clear messages from TOML parsing failures
-
Command failures : Logs errors but continues watching
-
Signal handling : Graceful shutdown on
Ctrl+C
See CONTRIBUTING for setup and contribution guidelines.
MIT © Michael George
See ADRs for detailed architecture decision records: