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