Perch is a tool that lets you run commands in response to file changes.
The quickest way to install Perch is via the installation script.
curl -fsSL https://raw.githubusercontent.com/uint4096/perch/main/installation/script.sh | bashThe script places the binary in your $PATH and configures Perch to run as a background service. You can see the contents of the installation script.
You can clone this repo and build it from source.
- OS: Linux (systemd), macOS
- Go: >=1.26
- make >=4.4.1
- Clone the repo
git clone https://github.com/uint4096/perch- Run make
makeBy default, make runs the service-install target: it builds the binary, creates an empty configuration, and starts Perch as a background service.
You can uninstall Perch by running make uninstall.
The configuration for Perch lives at $HOME/.config/perch/perchconf.toml. Here's an example configuration that echoes the names of changed .txt files within the /tmp/myDir directory.
[[Watches]]
Path = "/tmp/myDir"
Events = ["create", "remove", "write"]
Command = 'echo "changed file: $PERCH_TARGET_FILE. Events: $PERCH_TARGET_EVENTS"'
WorkingDir = "/tmp/myDir"
Include = ["*.txt"]
Debounce = 30In the configuration above, the echo command runs every time any file ending with .txt is created, deleted, or written to. Command can be a shell command or a path to an executable script.
Path can be either a file or a directory. For directories, Perch recursively resolves any subdirectories.
Perch exposes the following environment variables which you can use within the Command config:
$PERCH_TARGET_FILE: The full path to the file that changed.$PERCH_TARGET_EVENTS: A list of change events as space-separated strings (unordered). Quick successive events can overwrite earlier ones.$PERCH_TARGET_DELETED:trueif the target file no longer exists during command execution (i.e. it was deleted),falseotherwise.
Note: Globstar (**) syntax is not yet supported.
See the configuration reference for a complete list of options.
Running the installation script automatically configures Perch as a background service. If you're building from source, you can use the minimal service files (perchd.service for systemd, perchd.plist for launchd) in the installation directory to get started.
Note: Perch reads its configuration once at startup, so restart the service after editing perchconf.toml for the changes to take effect.
The installation script configures Perch to run as a systemd service under your user account, so it doesn't require root access.
systemctl --user status perchd.servicejournalctl --user -u perchd.service -fsystemctl --user restart perchd.servicePerch runs as a launchd user agent under your user account on macOS.
launchctl print gui/$(id -u)/com.perch.perchdPerch writes its output to ~/Library/Logs/perchd.log.
tail -f ~/Library/Logs/perchd.loglaunchctl kickstart -k gui/$(id -u)/com.perch.perchd| Command | Description |
|---|---|
perch |
Run the watcher in the foreground using the configured watches |
perch validate |
Verify whether the config file is valid |
perch version |
Print the current version |
perch help |
Print usage information |
Perch is licensed under the GNU General Public License v3.0 or later. See LICENSE for the full text.