A small Bash utility that reruns a command when files change.
It is designed to be embedded into another project (for example in a
scripts/ directory) rather than installed globally.
watch.sh monitors files in one or more directories and restarts a
given command whenever a change is detected.
It supports multiple backends:
inotifywait (Linux)fswatch (macOS / cross-platform)From this repository, install into another project:
make install TARGET_DIR=../your-project/scripts
This will copy the script to:
../your-project/scripts/watch.sh
Alternatively, create a symlink (recommended during development):
make link TARGET_DIR=../your-project/scripts
From the target project:
./scripts/watch.sh [options] -- <command>
Example:
./scripts/watch.sh -e js,ts -- node server.js
Option Description
—————- ——————————————————
-w <dir> Directory to watch (default: .)
-e <exts> File extensions (default: js,mjs,cjs,json,ts)
-i <pattern> Ignore pattern (can be used multiple times)
-d <secs> Restart delay in seconds (default: 1)
-s <signal> Signal used to stop the process (default: SIGTERM)
-k <secs> Time before force kill (default: 3)
-c Clear screen before restarting
-v Enable verbose output
-h Show help
Watch a Node.js app:
./scripts/watch.sh -e js -- node server.js
Watch multiple directories:
./scripts/watch.sh -w src -w config -- npm run dev
Ignore directories:
./scripts/watch.sh -i node_modules -i dist -- npm start
Clear screen on restart:
./scripts/watch.sh -c -- npm run dev
inotifywait or
fswatchMIT