https://github.com/tmc/watcher
watcher is a simple filesystem event watcher
https://github.com/tmc/watcher
Last synced: 11 months ago
JSON representation
watcher is a simple filesystem event watcher
- Host: GitHub
- URL: https://github.com/tmc/watcher
- Owner: tmc
- License: mit
- Created: 2012-10-05T19:08:20.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2022-02-24T18:44:38.000Z (over 4 years ago)
- Last Synced: 2024-12-02T20:49:59.704Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 71
- Watchers: 4
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# watcher
[](https://pkg.go.dev/github.com/tmc/watcher)
Command watcher is a file watcher that executes a command when files change.
It can be used to automatically run tests, build code, or any other command when files in a directory change.
## Installation
Prerequisites: Go Installation
You'll need Go 1.23 or later. [Install Go](https://go.dev/doc/install) if you haven't already.
Setting up your PATH
After installing Go, ensure that `$HOME/go/bin` is in your PATH:
For bash users
Add to `~/.bashrc` or `~/.bash_profile`:
```bash
export PATH="$PATH:$HOME/go/bin"
```
Then reload your configuration:
```bash
source ~/.bashrc
```
For zsh users
Add to `~/.zshrc`:
```bash
export PATH="$PATH:$HOME/go/bin"
```
Then reload your configuration:
```bash
source ~/.zshrc
```
### Install
```console
go install github.com/tmc/watcher@latest
```
### Run directly
```console
go run github.com/tmc/watcher@latest [arguments]
```
## Usage:
watcher [flags] [command to execute and args]
-c clear terminal before each run
-depth int
recursion depth (default 1)
-dir string
directory root to use for watching (default ".")
-ignore string
comma-separated list of glob patterns to ignore
-quiet duration
quiet period after command execution (default 800ms)
-v verbose
-wait duration
time to wait between change detection and exec (default 10ms)
## Features
- Watch directories recursively with configurable depth
- Ignore files based on glob patterns (e.g., \`-ignore "\*.tmp,\*.log"\`)
- Automatically detects and watches newly created directories
- Graceful termination on SIGINT/SIGTERM
- Configurable quiet period to avoid rapid execution
- Configurable wait time between file change and command execution
## Common Use Cases
- Run tests when source files change
- Trigger build steps in development
- Refresh browsers or servers
- Auto-compile code during development
## Example Use:
In Shell A:
```console
$ go install github.com/tmc/watcher@latest
$ mkdir /tmp/foo; cd /tmp/foo
$ watcher -v echo "triggered"
running echo triggered
triggered
```
Now, In Shell B:
```console
$ touch /tmp/foo/oi
```
Every time /tmp/foo changes the echo will be re-executed.
License: ISC