8000 GitHub - tmc/watcher: watcher is a simple filesystem event watcher
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

tmc/watcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

watcher

Go Reference

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

export PATH="$PATH:$HOME/go/bin"

Then reload your configuration:

source ~/.bashrc
For zsh users

Add to ~/.zshrc:

export PATH="$PATH:$HOME/go/bin"

Then reload your configuration:

source ~/.zshrc

Install

go install github.com/tmc/watcher@latest

Run directly

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:

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

$ touch /tmp/foo/oi

Every time /tmp/foo changes the echo will be re-executed.

License: ISC

About

watcher is a simple filesystem event watcher

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0