Watch the files in a directory and run a custom command of your choice
{code}
watch *.json "echo 'config file updated!'"
{code}
The following environment variables will be available to your command
- watcher_added - A JSON array of relative paths added in the watch directory
- watcher_removed - A JSON array of relative paths removed in the watch directory
- watcher_changed - A JSON array of relative paths changed in the watch directory
{code}
set command = "echo 'You added \${item}!'"
watch command="foreach '\${watcher_added}' \${command}" --verbose
{code}
Note in the above example, the ${watcher_added} and ${command} env vars in the "inner" command are escaped.
We also set an intermediate env var to hold the command to keep from needing to "double escape" it.
This command will run in the foreground until you stop it. When you are ready to shut down the watcher, press Ctrl+C.