watchexec/doc/watchexec.1.ronn

204 lines
11 KiB
Plaintext
Raw Normal View History

2016-10-29 19:08:55 +02:00
watchexec(1) -- execute commands when watched files change
==========================================================
## SYNOPSIS
2022-01-15 03:19:16 +01:00
watchexec [`--exts` | `-e` <extensions>]... [`--filter` | `-f` <pattern>]... [`--ignore` | `-i` <pattern>]... [`--watch` | `-w` <path>]... [`--restart` | `-r`] [`--clear` | `-c`] [`--postpone` | `-p`] [`--force-poll` <interval>] [`--debounce` | `-d` <interval>] [`--no-vcs-ignore`] [`--no-default-ignore`] [`--verbose` | `-v` | `-vv` | `-vvv` | `-vvvv`] [`--changes-only`] [`--version` | `-V`] [--] <command> [<argument>...]
2016-10-29 19:08:55 +02:00
## DESCRIPTION
2016-11-17 14:46:23 +01:00
Recursively monitors the current directory for changes, executing the command when a filesystem change is detected. By default, watchexec uses efficient kernel-level mechanisms to watch for changes.
2016-10-29 19:08:55 +02:00
At startup, the specified <command> (passing any supplied <argument>s) is run once, and watchexec begins monitoring for changes.
## OPTIONS
2017-02-05 19:29:38 +01:00
* <command>:
Command to run when watched files are modified, and at startup, unless `--postpone` is specified. All <argument>s are passed to <command>. If you pass flags to the command, you should separate it with `--`, for example: `watchexec -w src -- rsync -a src dest`.
2016-10-29 19:08:55 +02:00
Behaviour depends on the value of `--shell`: for all except `none`, every part of <command> is joined together into one string with a single ascii space character, and given to the shell as described. For `none`, each distinct element of <command> is passed as per the execvp(3) convention: first argument is the program, as a file or searched in the `PATH`, rest are arguments.
2016-10-29 19:08:55 +02:00
* `-e`, `--exts` <extensions>:
2019-10-10 12:39:13 +02:00
Comma-separated list of file extensions to filter by. Leading dots (.rs) are allowed. (This is a shorthand for `-f`).
2016-10-29 19:08:55 +02:00
* `-f`, `--filter` <pattern>:
2017-02-05 19:29:38 +01:00
Ignores modifications from paths that do not match <pattern>. This option can be specified multiple times, where a match on any given pattern causes the path to trigger <command>.
2016-10-29 19:08:55 +02:00
2017-03-26 18:25:13 +02:00
* `-s`, `--signal`:
Sends the specified signal (e.g. `SIGKILL`) to the command. Defaults to `SIGTERM`.
2021-04-10 16:51:20 +02:00
* `--shell` <shell>:
Change the shell used to run the command. Set to `none` to run the command directly without a shell.
The special value `powershell` will use Microsoft Powershell's calling convention, otherwise `SHELL -c COMMAND`.
On Windows, the additional `cmd` special value uses CMD.EXE calling convention.
2021-04-16 16:11:16 +02:00
The `none` value is especially useful in combination with `--signal`, as the signal is then sent directly to the running command. While `--shell=none` is a little more performant than the default, it prevents using shell-features like pipes and redirects.
2021-04-10 16:51:20 +02:00
If not a special value, the string provided may contain arguments to the shell as long as that is kept simple: the string is split along whitespace, and used as per execvp(3): first is shell program, rest are arguments to the shell, then `-c` is added, and finally the `COMMAND`.
See the [EXAMPLES] for uses of each of these.
2021-04-10 16:51:20 +02:00
* `--no-shell`:
Deprecated. Alias for `--shell=none`.
* `-n`:
Shorthand for `--shell=none`.
2017-04-06 22:51:52 +02:00
* `--no-meta`:
Ignore metadata changes.
2020-06-23 13:43:55 +02:00
* `--no-environment`:
Do not set WATCHEXEC_*_PATH environment variables for the command.
2020-06-23 13:43:55 +02:00
2017-02-05 19:29:38 +01:00
* `-i`, `--ignore` <pattern>:
2016-10-29 19:08:55 +02:00
Ignores modifications from paths that match <pattern>. This option can be specified multiple times, and a match on any pattern causes the path to be ignored.
2017-02-05 19:29:38 +01:00
* `-w`, `--watch` <path>:
Monitor a specific path for changes. By default, the current working directory is watched. This may be specified multiple times, where a change in any watched directory (and subdirectories) causes <command> to be executed.
2016-10-29 19:08:55 +02:00
* `-r`, `--restart`:
Terminates the command if it is still running when subsequent file modifications are detected. By default, sends `SIGTERM`; use `--signal` to change that.
* `-W`, `--watch-when-idle`:
Ignore events while the process is still running. This is distinct from `--restart` in that with this option, events received while the command is running will not trigger a new run immediately after the current command is done.
This behaviour will become the default in v2.0.
2016-10-29 19:08:55 +02:00
2021-07-21 14:56:35 +02:00
* `--no-process-group`:
Do not use a process group when running <command>.
2016-10-29 19:08:55 +02:00
* `-c`, `--clear`:
Clears the screen before executing <command>.
* `-p`, `--postpone`:
Postpone execution of <command> until the first file modification is detected.
* `--force-poll` <interval>:
2016-11-17 14:46:23 +01:00
Poll for changes every <interval> ms instead of using system-specific notification mechanisms (such as inotify). This is useful when you are monitoring NFS shares.
2016-10-29 19:08:55 +02:00
* `-d`, `--debounce`:
2021-07-21 13:44:24 +02:00
Set the timeout between detected change and command execution, to avoid restarting too frequently when there are many events; defaults to 100ms.
2016-10-29 19:08:55 +02:00
* `--no-vcs-ignore`:
Skip loading of version control system (VCS) ignore files. By default, watchexec loads .gitignore, .hgignore, and other such files in the current directory (or child directories as applicable) and uses them to filter change events.
2016-10-29 19:08:55 +02:00
* `--no-project-ignore`, `--no-ignore` (deprecated alias):
Skip loading of project-local ignore files (include VCS ignore files). By default, watchexec loads .ignore, .gitignore, .hgignore, and other such files in the current directory (or child directories as applicable) and uses them to filter change events.
2017-04-26 03:15:40 +02:00
* `--no-default-ignore`:
Skip default ignore statements. By default, watchexec ignores common temporary files for you, for example `*.swp`, `*.pyc`, and `.DS_Store`, as well as the data directories of known VCS: `.bzr`, `_darcs`, `.fossil-settings`, `.git`, `.hg`, `.pijul`, and `.svn`.
2017-04-26 03:15:40 +02:00
* `--no-global-ignore`:
Skip loading of global ignore files. By default, watchexec loads $HOME/.gitignore and other such global files and uses them to filter change events.
2022-01-15 03:19:16 +01:00
* `-v`, `--verbose`, `-vv`, etc:
Prints diagnostic and debugging messages to STDERR. Increase the amount of `v`s to get progressively more output: for bug reports use **three**, and for deep debugging **four** can be helpful.
* `--print-events`, `--changes-only` (deprecated alias):
2022-01-15 03:26:35 +01:00
Prints the events (changed paths, etc) that have triggered an action to STDERR.
2022-01-15 03:26:57 +01:00
* `-N`, `--notify`:
Sends desktop notifications on command start and command end.
* `-V`, `--version`:
Print the version of watchexec.
* `-h`, `--help`:
Print a help message.
2016-10-29 19:08:55 +02:00
## ENVIRONMENT
In variables that contain lists of paths, the separator is as for the `$PATH` environment variable (a colon, or semicolon on Windows).
### Set on child processes
Processes started by watchexec have environment variables set describing the changes observed.
`$WATCHEXEC_COMMON_PATH` is set to the longest common path of all of the below variables, and so should be prepended to each path to obtain the full/real path. Then:
- `$WATCHEXEC_CREATED_PATH` is set when files/folders were created
- `$WATCHEXEC_REMOVED_PATH` is set when files/folders were removed
- `$WATCHEXEC_RENAMED_PATH` is set when files/folders were renamed
- `$WATCHEXEC_WRITTEN_PATH` is set when files/folders were modified
- `$WATCHEXEC_META_CHANGED_PATH` is set when files/folders' metadata were modified
- `$WATCHEXEC_OTHERWISE_CHANGED_PATH` is set for every other kind of pathed event
These variables may contain multiple paths: these are separated by the platform's path separator, as with the `PATH` system environment variable. On Unix that is `:`, and on Windows `;`. Within each variable, paths are deduplicated and sorted in binary order (i.e. neither Unicode nor locale aware).
One thing to take care of is assuming inherent behaviour where there is only chance. Notably, it could appear as if the `RENAMED` variable contains both the original and the new path being renamed. In previous versions, it would even appear on some platforms as if the original always came before the new. However, none of this was true. It's impossible to reliably and portably know which changed path is the old or new, "half" renames may appear (only the original, only the new), "unknown" renames may appear (change was a rename, but whether it was the old or new isn't known), rename events might split across two debouncing boundaries, and so on.
This variable group can be disabled or limited with `--no-environment` (doesn't set any of these variables) and `--no-meta` (ignores metadata changes).
### Read upon startup
- `$WATCHEXEC_FILTERER`: select the filterer implementation: `globset` (default), or `tagged` (experimental).
- `$WATCHEXEC_IGNORE_FILES`: a list of paths to additional ignore files to be loaded.
- `$WATCHEXEC_FILTER_FILES`: a list of paths to additional "Tagged" filter files to be loaded (when enabled).
- `$RUST_LOG`: use for advanced verbose logging configuration. Refer to tracing-subscriber for documentation.
## FILES
### Supported project ignore files
- Git: `.gitignore` at project root and child directories, `.git/info/exclude`, and the file pointed to by `core.excludesFile` in `.git/config`.
- Mercurial: `.hgignore` at project root and child directories.
- Bazaar: `.bzrignore` at project root.
- Darcs: `_darcs/prefs/boring`
- Fossil: `.fossil-settings/ignore-glob`
- Ripgrep/Watchexec/generic: `.ignore` at project root and child directories.
Note that VCS ignore files (Git, Mercurial, Bazaar, Darcs, Fossil) are only used if the corresponding VCS is discovered to be in use for the project/origin. For example, a `.bzrignore` in a Git repository will be discarded.
### Supported global ignore files
- Git (if core.excludesFile is set): the file at that path
- Git (otherwise): the first found of `$XDG_CONFIG_HOME/git/ignore`, `%APPDATA%/.gitignore`, `%USERPROFILE%/.gitignore`, `$HOME/.config/git/ignore`, `$HOME/.gitignore`.
- Bazaar: the first found of `%APPDATA%/Bazzar/2.0/ignore`, `$HOME/.bazaar/ignore`.
- Watchexec: the first found of `$XDG_CONFIG_HOME/watchexec/ignore`, `%APPDATA%/watchexec/ignore`, `%USERPROFILE%/.watchexec/ignore`, `$HOME/.watchexec/ignore`.
Note that like for project files, Git and Bazaar global files will only be used for the corresponding VCS as used in the project.
2016-10-29 19:08:55 +02:00
## EXAMPLES
Rebuild a project when source files change:
$ watchexec make
Watch all HTML, CSS, and JavaScript files for changes:
$ watchexec -e html,css,js make
Run tests when source files change, clearing the screen each time:
$ watchexec -c make test
2017-02-05 19:29:38 +01:00
Launch and restart a node.js server:
2016-10-29 19:08:55 +02:00
$ watchexec -r node app.js
2017-02-05 19:29:38 +01:00
Watch lib and src directories for changes, rebuilding each time:
$ watchexec -w lib -w src make
Use without shell:
$ watchexec -n -- zsh -x -o shwordsplit scr
Use with powershell (default on windows from 2.0):
$ watchexec --shell=powershell -- test-connection localhost
Use with cmd (default on windows until 2.0):
$ watchexec --shell=cmd -- dir
Use with a different unix shell:
$ watchexec --shell=bash -- 'echo $BASH_VERSION'
Use with a unix shell and options:
$ watchexec --shell='zsh -x -o shwordsplit' -- scr