Skip to content

Zig asynchronous directory file change watcher library for Windows, macOS and Linux.

License

Notifications You must be signed in to change notification settings

OsakiTsukiko/zigmon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zig bindings for the C library dmon.

Getting started

Copy (or use git submodule) zigmon to a subdirectory of your project and add the following to your build.zig.zon .dependencies:

    .zigmon = .{ .path = "libs/zigmon" },

Then in your build.zig add:

pub fn build(b: *std.Build) void {
    const exe = b.addExecutable(.{ ... });

    const zigmon = b.dependency("zigmon", .{});
    exe.root_module.addImport("zigmon", zigmon.module("root"));
    exe.linkLibrary(zigmon.artifact("zigmon"));
}

Example Code

const std = @import("std");
const zm = @import("zigmon").ZigMon;

fn watch_callback(
    _: zm.WatchID, // watch_id
    _: zm.Actions, // action
    // if you know what you are doing you can change the
    // type of the following 3 arguments to `[*:0]const`
    // only use `old_filepath` for `move` action
    // it will be null otherwise
    _: ?[*:0]const u8, // root_dir
    _: ?[*:0]const u8, // filepath
    _: ?[*:0]const u8, // old_filepath
    _: ?*anyopaque, // user
) void {
    std.debug.print("NEW EVENT\n", .{});
}


pub fn main() !void {
    zm.init();

    _ = zm.watch(
        "/path/to/directory", 
        @as(*const anyopaque, @ptrCast(&watch_callback)),
        .recursive,
        null,
    );

    while (true) {}

    zm.deinit();
}

Useful

To better understand how to use, look into src/zigmon.zig and libs/dmon/dmon.h.

About

Zig asynchronous directory file change watcher library for Windows, macOS and Linux.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published