introducing libzmx
·
erock's devlog
use zmx as a zig module
- I'm excited to announce zmx can now be used as a zig module to programmtically interact build session persistence in your zig project. Projects can use this instead of embedding the zmx binary and exec spawning commands through the zmx cli. This zig module is just a thin wrapper around a unix socket ipc wire protocol to interface with the running zmx daemon that controls the terminal session.
- libzmx-commit
quick start
- The library in `src/lib.zig` is importable as the `zmx` package from other Zig projects. All functions take `(alloc, io, ...)` from `std.process.Init`.
- Read the source code to learn about what you can do with zmx
// build.zig.zon .dependencies = .{ .zmx = .{ .url = "git+https://github.com/neurosnap/zmx#<commit>", .hash = "...", }, } // build.zig const zmx = b.dependency("zmx", .{ .target = target, .optimize = optimize }); exe_mod.addImport("zmx", zmx.module("zmx")); // your source const zmx = @import("zmx"); const exit_code = try zmx.run(gpa, io, "my-session", &.{"echo", "hi"}, .{}); const sessions = try zmx.list(gpa, io); defer { for (sessions) |s| s.deinit(gpa); gpa.free(sessions); }
notes
- `zmx.run` creates the session (and daemon) if it doesn't exist, no need to call `zmx.create` first.
- `zmx.create` is only available when the package is built with `-Ddaemon=true` (the default).
- See examples
fin
- That's it! I'll start compiling a list of projects that use libzmx so feel free to contact me with your project and I can add it!