wr -- watch files and run a command when they change
wr [-cvV] command [file ...]
wr will watch the set of files and directories specified on the
command line, and run the specified command when any of the files
changes. For each file operand which is a directory, all the files
in the directory (recursively) will be watched.
If no files are specified, it's as if you passed "." as the file parameter.
The following options are available:
-c --chime minutes
Write a diagnostic message after
minuteshave elapsed since last running a command, to remind you
wris running. The default is 5 minutes. Use the value 0 to disable the chime.
Generate additional diagnostic information.
Display stdout and stderr in specific colors; color values:
black red green yellow blue magenta cyan white.
Use exec instead of spawn to run the command.
-p --poll seconds
Use a polling file watcher. The default is to use a non-polling file watcher. The non-polling file watcher may have a relatively small maximum number of files it can watch (200), but the polling file watcher has no maximum. The polling file watcher may incur delays between a file changing and the command running, compared to the non-polling file watcher.
Display the version number and exit.
The following is how to run make when any file in the current directory changes:
More likely you can whittle the list of source files checked a bit. The
following will run make any file in the
wr make src doc test
To run a command with arguments, quote the command you want to run. The
following will run the command "
echo a file changed" when any file in the
current directory changes:
wr "echo a file changed"
wr will not normally exit. Use ctrl-c or equivalent to kill the process from the command-line.
Diagnostic information from
wr will be written to stderr.
If the current directory has a
.wr file in it, that file is assumed
to have the contents of a
wr invocation in it. Options, option/value
pairs, the command to run, and each file to be watched should be
specified on separate lines.
The file may contain blank lines or lines starting with the
which are considered comments.
The stdout and stderr from the command being run are passed directory to
wr's stdout and stderr. stdin for the command will not be available
for the command.
The command will be run in either spawn or exec mode, as determined by command-line options. Here are the differences:
- the command will not be parsed, as will be run as given
- should handle i/o redirection shell operators
- stdout and stderr output will be buffered until the command is complete
- the command will be parsed into space separated tokens, probably misinterpreting any quotes you have in your command
- will not handle i/o redirection shell operators
- stdout and stderr output will not be buffered
wr is a port of Patrick Mueller's run-when-changed.py
script to node.
2012-05-03: version 1.2.0
- issue 8 - add elapsed time to success and failure messages
- fixed bug where wr fired off it's command when the access time changed on a file
2012-01-11: version 1.1.0
- issue 1 - chime should print the time
- issue 2 - chime should default to 5 minutes
- issue 3 - .wr file parser should accept option/value on a single line
- issue 5 - provide option to use stat-based polling
- issue 6 - use spawn instead of exec to run commands
- issue 7 - colorize stdout and stderr
2012-01-10: version 1.0.1
- fixed some stupid bugs
2012-01-09: version 1.0.0
- initial release