hnhdigital-os / fs-watcher

Provides the ability to watch folders for changes and call a binary in response.

Repository from Github https://github.comhnhdigital-os/fs-watcherRepository from Github https://github.comhnhdigital-os/fs-watcher

FS-WATCHER

Provides the ability to watch folders for changes and call a binary in response.

Latest Stable Version License: MIT Donate to this project using Patreon

This package has been developed by H&H|Digital, an Australian botique developer. Visit us at hnh.digital.

Requirements

  • PHP 7.3 (min)
  • php-inotify (pecl install inotify)

Installation

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

Updating

This tool provides a self-update mechanism. Simply run the self-update command.

fs-watcher self-update

How to use

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.

watch:now or watch:background

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

watch:load

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-ARGUMENTS

Example:

/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

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Provides the ability to watch folders for changes and call a binary in response.


Languages

Language:PHP 100.0%