# watchexec
> Execute commands when watched files change

## Summary
A file watcher that executes commands on changes. Watches directories, filters by extension or glob, debounces events, and handles process restarts cleanly.

## Capabilities
- Watches files and directories for changes
- Filter by file extension, glob pattern, or ignore patterns
- Debouncing to avoid rapid re-execution
- Clean process restart with signal handling

## When to Use
- Auto-running tests when source files change
- Rebuilding a project on file save
- Need a language-agnostic file watcher

## When NOT to Use
- Your build tool already has watch mode (e.g., cargo watch, nodemon)

## Usage Patterns
### Run tests on file changes
```
watchexec -e py -- pytest
```
Runs pytest whenever a .py file changes

### Restart a server on changes
```
watchexec -r -- ./server
```
Restarts the server process when files change

## Installation
- **homebrew**: `brew install watchexec`
- **cargo**: `cargo install watchexec-cli`
- **pacman**: `sudo pacman -S watchexec`

---
Source: https://littlescripts.sh/tools/watchexec
