Listener for syncthing events - runs command on trigger
Find a file
2025-04-01 13:45:34 -07:00
src skip old events on first run 2025-04-01 13:45:34 -07:00
.envrc initial commit 2025-03-31 15:45:23 -07:00
.gitignore add gitignore 2025-04-01 08:46:27 -07:00
build.zig skip old events on first run 2025-04-01 13:45:34 -07:00
build.zig.zon skip old events on first run 2025-04-01 13:45:34 -07:00
devfile.yaml add AI generated whatever 2025-03-31 16:54:36 -07:00
LICENSE initial commit 2025-03-31 15:45:23 -07:00
README.md add AI generated whatever 2025-03-31 16:54:36 -07:00

Syncthing Events Handler

A command-line application written in Zig that monitors Syncthing events and executes configured actions based on file changes.

Features

  • Continuously polls Syncthing events API
  • Configurable event filtering based on folder and path patterns
  • Executes custom commands when matching events are detected
  • Supports JSON, ZON, or YAML configuration formats

Installation

zig build

The executable will be created in zig-out/bin/syncthing_events

Configuration

Create a configuration file in either JSON, ZON, or YAML format. Example (in JSON):

{
  "syncthing_url": "http://localhost:8384",
  "poll_interval_ms": 1000,
  "watchers": [
    {
      "folder": "default",
      "path_pattern": ".*\\.pdf$",
      "command": "pdftotext \"${path}\" \"${path}.txt\""
    },
    {
      "folder": "photos",
      "path_pattern": ".*\\.(jpg|jpeg|png)$",
      "command": "convert \"${path}\" -resize 800x600 \"${path}.thumb.jpg\""
    }
  ]
}

Configuration Options

  • syncthing_url: Base URL of your Syncthing instance (default: http://localhost:8384)
  • poll_interval_ms: How often to check for new events in milliseconds (default: 1000)
  • watchers: Array of event watchers with the following properties:
    • folder: Syncthing folder ID to watch
    • path_pattern: Regular expression to match file paths
    • command: Command to execute when a match is found. Supports variables:
      • ${path}: Full path to the changed file
      • ${folder}: Folder ID where the change occurred
      • ${type}: Event type (e.g., "ItemFinished")

Usage

# Run with default configuration file (config.json)
syncthing_events

# Specify a custom configuration file
syncthing_events --config my-config.yaml

# Override Syncthing URL
syncthing_events --url http://syncthing:8384

Development

This project uses a devfile for consistent development environments. To start developing:

  1. Install a compatible IDE/editor that supports devfile (e.g., VS Code with DevContainer extension)
  2. Open the project folder
  3. The development container will be automatically built with Zig 0.14.0

Running Tests

zig build test

License

MIT License