Provides the ability to watch folders for changes and call a binary in response.
This package has been developed by H&H|Digital, an Australian botique developer. Visit us at hnh.digital.
- PHP 7.3 (min)
- php-inotify (
pecl install inotify)
Download the latest build:
curl -o ./fs-watcher -LsS https://github.com/hnhdigital-os/fs-watcher/raw/master/builds/fs-watcher
chmod a+x ./fs-watcher
Move it local bin:
sudo mv ./fs-watcher /usr/local/bin/fs-watcher
This tool provides a self-update mechanism. Simply run the self-update command.
fs-watcher self-update
USAGE: fs-watcher <command> [options] [arguments]
config <set|get|reset> [key] [value]
Manage the configuration for this utility.
self-update Check if there is a new version and update.
self-update [--tag=?]
Update this binary to a specific tagged release.
self-update [--check-release=?]
Returns the current binary version.
watch:now [watch-path] [binary-path] [--script-arguments=""]
Specify the path to watch, when a file change is detected
this utility will call the specified binary at the path with the
specific script arguments.
watch:background [watch-path] [binary-path] [--script-arguments=""]
Runs process in the background. Specify the path to watch,
when a file change is detected this utility will call the
specified binary at the path with the specific script arguments.
watch:load Load watchers from a config file.
watch:list List all current watchers.
watch:kill [pid]
Kill a specific process ID for a current watcher.
watch:kill all Kills all the watchers.
watch:log [pid]
View the current log for a specific process ID.
watch:log [--where]
Returns the path of the log files.
watch:log [pid] [--clear]
Clears the logs for a specific process ID.
watch:log [--clear]
Clears all the logs.
For example, if we want to watch for changes in the /some/folder/example path and have all changes notified to the executable file /some/bin/binary-file.
Note: This utility replaces the following placeholders {{root-path}}, {{file-path}} and {{event-id}} in the script-arguments argument with values. Both path arguments do not need quotations as they will be added automatically.
fs-watcher watch:background /some/folder/example /some/bin/binary-file --script-arguments="{{root-path}} {{file-path}} {{event-id}}"
On each file change in the given root folder, the following command execution will occur:
/some/bin/binary-file "/some/folder/example" "/some/folder/example/new-file" 256
Instead of calling this utility for each folder you want to watch, you can use the watch:load command to load a YAML config file.
This config file is in the format:
WATCH-PATH:
- BINARY-PATH: SCRIPT-ARGUMENTSExample:
/some/folder/example:
- /some/bin/binary-file: {{root-path}} {{file-path}} {{event-id}}And then run this to load and start the watcher:
fs-watcher watch:load example.yml
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.