with-watch
with-watch is a Rust-based command rerun watcher that repeats a delegated command when its inferred or explicit filesystem inputs change.
It performs one initial run immediately after input inference, watcher setup, and baseline capture, then listens for later filesystem changes.
Why use with-watch
- Keep familiar CLI tools such as
cat,cp,sed, andfind. - Let
with-watchinfer watched inputs for common file-oriented commands. - Declare explicit inputs with
exec --inputwhen you want fully predictable reruns.
Install
Tag contract:with-watch@v<semver>
- macOS/Linux:
brew install delinoio/tap/with-watch - Homebrew installs prebuilt archives on macOS Intel, macOS Apple Silicon, Linux amd64, and Linux arm64
cargo-binstall:
Quick start
Rerun a file reader when its input changes:Input inference model
- Passthrough mode and
--shelluse built-in command adapters first. - Known outputs, inline scripts, and output redirects are filtered out of the watch set.
- Safe pathless defaults are intentionally narrow:
ls,dir,vdir,du, andfind. - If
with-watchcannot infer safe filesystem inputs, it fails instead of guessing.
Recognized command inventory
with-watch --help includes the full recognized command inventory in analyzer order.
Wrapper commands:
env,nice,nohup,stdbuf,timeout
cp,mv,install,ln,link,rm,unlink,rmdir,shredsort,uniq,split,csplit,teegrep,egrep,fgrep,sedawk,gawk,mawk,nawkfind,xargs,tar,touch,truncatechmod,chown,chgrp,dd
cat,tac,head,tail,wc,nl,od,cut,fmt,fold,paste,pr,trexpand,unexpand,stat,readlink,realpathmd5sum,b2sum,cksum,sum,sha1sum,sha224sum,sha256sum,sha384sumsha512sum,sha512_224sum,sha512_256sumbase32,base64,basenc,comm,join,cmp,tsort,shuf
find,ls,dir,vdir,du
echo,printf,seq,yes,sleep,date,uname,pwd,true,falsebasename,dirname,nproc,printenv,whoami,logname,users,hostidnumfmt,mktemp,mkdir,mkfifo,mknod
exec --input when you want explicit watch inputs.
When exec —input is required
Some commands do not expose meaningful filesystem inputs on their own. For example,echo hello has nothing safe to watch.
In those cases, use exec --input to declare the watch set explicitly:
with-watch reruns the delegated command unchanged. It does not inject changed file paths into argv or environment variables.
Shell support boundaries
--shellsupports command-line expressions with&&,||, and|.- Input redirects (
<,<>) become watched inputs. - Output redirects (
>,>>,&>,&>>,>|) are treated as outputs and filtered from watching. - Full shell control-flow is out of scope for v1.
Rerun behavior
with-watchalways performs one initial run after it has inferred inputs and armed the watcher, even before any external filesystem change occurs.- Default rerun filtering uses content hashes.
--no-hashswitches to metadata-only comparison.- Self-mutating commands such as
sed -i.bak -e 's/old/new/' config.txtrefresh their baseline after each run so they do not loop on their own writes. - Replace-style writers remain watchable because path inputs subscribe from the nearest existing directory anchor.
Logging
with-watchreads diagnostictracingfilters only fromWW_LOG.- Diagnostic logs are off by default.
- Set
WW_LOG=with_watch=infofor normal watcher diagnostics orWW_LOG=with_watch=debugfor deeper troubleshooting. RUST_LOGdoes not affectwith-watchlogging.WITH_WATCH_LOG_COLORandNO_COLORstill control ANSI log coloring.- Fatal user-facing errors still print to stderr even when diagnostic logging is off.