From 609aedf5cb38ed28088f04365511841f7d24fe48 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 1 Oct 2020 21:02:43 +0000 Subject: [PATCH] update watchexec cheat sheet --- watchexec/README.md | 66 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/watchexec/README.md b/watchexec/README.md index 809e9d9..59599fe 100644 --- a/watchexec/README.md +++ b/watchexec/README.md @@ -13,22 +13,72 @@ Use the `@beta` tag for pre-releases. ## Cheat Sheet -Watch all JavaScript, CSS and HTML files in the current directory and all -subdirectories for changes, running `make` when a change is detected: +`watchexec` runs a given command when any files in watched directories change. \ +It respects `.[git]ignore`. + +The full `--help` detailed and very useful. Here's the shortlist of what I find +most useful: + +```txt +-w, --watch ./src/ watch the given directory +-e, --exts js,html,css watch only the given extensions +-i, --ignore '*.md' do not watch the given pattern +-d, --debounce 5000 the minimum number of milleseconds + to wait between changes + +-r, --restart restart the process (for servers and such) +-s, --signal SIGHUP like -r, but with a signal (ex: SIGHUP) +-c, --clear clear the screen between command runs +-W (wait) ignore all changes while the command runs + +-- npm start what command to run, which its arguments + +--no-ignore disregard both .ignore and .gitignore +--no-vcs-ignore disregard only .gitignore +--no-default-ignore disregard built-in ignore lists +``` + +### How to use + +Example: List the directory when any files change. ```bash -watchexec --exts js,css,html make +watchexec -c -- ls -lah ``` -Call `make test` when any file changes in this directory/subdirectory, except -for everything below `target`: +### Advanced Usage Example + +Here's a "kitchen sink" example. ```bash -watchexec -i target make test +watchexec -c -r -s SIGKILL -d 2000 -W --verbose \ + -w ./src -w ./lib -w ./server.js \ + -e ts,js,sass,css,html \ + -i '.git' '*.min.js' -i '*.min.css' \ + -- npm run build ``` -Call `ls -la` when any file changes in this directory/subdirectory: +### How to use (Node, Go, Rust, rsync) + +These examples show how you might use this for builds, servers, and publishing +or deploying. ```bash -watchexec -- ls -la +# Node / npm +watchexec -W -- npm run build +watchexec -r -- npm start + +# Golang +watchexec -- go build . +watchexec -r -- go run . + +# Rust +watchexec -- cargo build --bin +watchexec -r -- cargo run --bin + +# rsync (local copy) +watchexec -- rsync -avhP ./ ./srv/MY_PROJECT/ + +# rsync (remote publish) +watchexec -- rsync -avhP ./ app@example.com:~/srv/MY_PROJECT/ ``` -- 2.25.1