refactor: finish moving ssh-* scripts to own installers
[webi-installers/.git] / watchexec / README.md
1 ---
2 title: watchexec
3 homepage: https://github.com/watchexec/watchexec
4 tagline: |
5   watchexec is a simple, standalone tool that watches a path and runs a command whenever it detects modifications.
6 ---
7
8 To update or switch versions, run `webi watchexec@stable` (or `@v1.17`, `@beta`,
9 etc).
10
11 ## Cheat Sheet
12
13 `watchexec` runs a given command when any files in watched directories change. \
14 It respects `.[git]ignore`.
15
16 Here's the shortlist of options we've found most useful:
17
18 ```txt
19 -w, --watch     ./src/      watch the given directory
20 -e, --exts      js,css      watch only the given extensions
21 -i, --ignore    '*.md'      do not watch the given pattern
22 -d, --debounce  5000        the minimum number of milleseconds
23                                 to wait between changes
24
25 -r, --restart               restart the process (for servers, etc)
26 -s, --signal    SIGHUP      like -r, but with a signal (ex: SIGHUP)
27 -c, --clear                 clear the screen between command runs
28 -W  (wait)                  ignore all changes as the command runs
29
30 --              npm start   what command to run, with its arguments
31
32 --no-ignore                 disregard both .ignore and .gitignore
33 --no-vcs-ignore             disregard only .gitignore
34 --no-default-ignore         disregard built-in ignore lists
35 ```
36
37 ### How to use
38
39 Example: List the directory when any files change.
40
41 ```bash
42 watchexec -c -- ls -lah
43 ```
44
45 ### Advanced Usage Example
46
47 Here's a "kitchen sink" example.
48
49 ```bash
50 watchexec -c -r -s SIGKILL -d 2000 -W --verbose \
51     -w ./src -w ./server.js \
52     -e js,css,html \
53     -i '*.md' -i 'package-lock.json' \
54     -- npm run build
55 ```
56
57 ### How to use (Node, Go, Rust, rsync)
58
59 These examples show how you might use this for builds, servers, and publishing
60 or deploying.
61
62 ```bash
63 # Node / npm
64 watchexec -W -- npm run build
65 watchexec -r -- npm start
66
67 # Golang
68 watchexec -- go build .
69 watchexec -r -- go run .
70
71 # Rust
72 watchexec -- cargo build --bin
73 watchexec -r -- cargo run --bin
74
75 # rsync (local copy)
76 watchexec -- rsync -avhP ./ ./srv/MY_PROJECT/
77
78 # rsync (remote publish)
79 watchexec -- rsync -avhP ./ app@example.com:~/srv/MY_PROJECT/
80 ```