typo fix and format update
[webi-installers/.git] / watchexec / README.md
index 782bbebdc0556971ea7a6e37868be009d63d4af1..1f5429a351dc270a18c54c14a1eaffb4b29a6235 100644 (file)
@@ -13,45 +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`.
 
-    $ watchexec --exts js,css,html make
+The full `--help` detailed and very useful. Here's the shortlist of what I find
+most useful:
 
-Call `make test` when any file changes in this directory/subdirectory, except
-for everything below `target`:
+```txt
+-w, --watch     ./src/      watch the given directory
+-e, --exts      js,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
 
-    $ watchexec -i target make test
+-r, --restart               restart the process (for servers, etc)
+-s, --signal    SIGHUP      like -r, but with a signal (ex: SIGHUP)
+-c, --clear                 clear the screen between command runs
+-W  (wait)                  ignore all changes as the command runs
 
-Call `ls -la` when any file changes in this directory/subdirectory:
+--              npm start   what command to run, with its arguments
 
-    $ watchexec -- ls -la
+--no-ignore                 disregard both .ignore and .gitignore
+--no-vcs-ignore             disregard only .gitignore
+--no-default-ignore         disregard built-in ignore lists
+```
 
-Call/restart `python server.py` when any Python file in the current directory
-(and all subdirectories) changes:
+### How to use
 
-    $ watchexec -e py -r python server.py
+Example: List the directory when any files change.
 
-Call/restart `my_server` when any file in the current directory (and all
-subdirectories) changes, sending `SIGKILL` to stop the child process:
+```bash
+watchexec -c -- ls -lah
+```
 
-    $ watchexec -r -s SIGKILL my_server
+### Advanced Usage Example
 
-Send a SIGHUP to the child process upon changes (Note: with using
-`-n | --no-shell` here, we're executing `my_server` directly, instead of
-wrapping it in a shell:
+Here's a "kitchen sink" example.
 
-    $ watchexec -n -s SIGHUP my_server
+```bash
+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
+```
 
-Run `make` when any file changes, using the `.gitignore` file in the current
-directory to filter:
+### How to use (Node, Go, Rust, rsync)
 
-    $ watchexec make
+These examples show how you might use this for builds, servers, and publishing
+or deploying.
 
-Run `make` when any file in `lib` or `src` changes:
+```bash
+# Node / npm
+watchexec -W -- npm run build
+watchexec -r -- npm start
 
-    $ watchexec -w lib -w src make
+# Golang
+watchexec -- go build .
+watchexec -r -- go run .
 
-Run `bundle install` when the `Gemfile` changes:
+# Rust
+watchexec -- cargo build --bin
+watchexec -r -- cargo run --bin
 
-    $ watchexec -w Gemfile bundle install
+# rsync (local copy)
+watchexec -- rsync -avhP ./ ./srv/MY_PROJECT/
+
+# rsync (remote publish)
+watchexec -- rsync -avhP ./ app@example.com:~/srv/MY_PROJECT/
+```