repos / zmx

session persistence for terminal processes
git clone https://github.com/neurosnap/zmx.git

commit
f03cdc1
parent
622a781
author
Eric Bower
date
2025-10-11 15:58:05 -0400 EDT
chore: pass config struct to all subcommands
6 files changed,  +20, -15
M src/attach.zig
+3, -2
 1@@ -3,6 +3,7 @@ const posix = std.posix;
 2 const xevg = @import("xev");
 3 const xev = xevg.Dynamic;
 4 const clap = @import("clap");
 5+const config_mod = @import("config.zig");
 6 
 7 const c = @cImport({
 8     @cInclude("termios.h");
 9@@ -28,7 +29,7 @@ const params = clap.parseParamsComptime(
10     \\
11 );
12 
13-pub fn main(socket_path_default: []const u8, iter: *std.process.ArgIterator) !void {
14+pub fn main(config: config_mod.Config, iter: *std.process.ArgIterator) !void {
15     var gpa = std.heap.GeneralPurposeAllocator(.{}){};
16     defer _ = gpa.deinit();
17     const allocator = gpa.allocator();
18@@ -47,7 +48,7 @@ pub fn main(socket_path_default: []const u8, iter: *std.process.ArgIterator) !vo
19     };
20     defer res.deinit();
21 
22-    const socket_path = res.args.@"socket-path" orelse socket_path_default;
23+    const socket_path = res.args.@"socket-path" orelse config.socket_path;
24 
25     const session_name = res.positionals[0] orelse {
26         std.debug.print("Usage: zmx attach <session-name>\n", .{});
M src/daemon.zig
+3, -2
 1@@ -3,6 +3,7 @@ const posix = std.posix;
 2 const xevg = @import("xev");
 3 const xev = xevg.Dynamic;
 4 const clap = @import("clap");
 5+const config_mod = @import("config.zig");
 6 
 7 const ghostty = @import("ghostty-vt");
 8 
 9@@ -99,7 +100,7 @@ const params = clap.parseParamsComptime(
10     \\
11 );
12 
13-pub fn main(socket_path_default: []const u8, iter: *std.process.ArgIterator) !void {
14+pub fn main(config: config_mod.Config, iter: *std.process.ArgIterator) !void {
15     var gpa = std.heap.GeneralPurposeAllocator(.{}){};
16     defer _ = gpa.deinit();
17     const allocator = gpa.allocator();
18@@ -118,7 +119,7 @@ pub fn main(socket_path_default: []const u8, iter: *std.process.ArgIterator) !vo
19     };
20     defer res.deinit();
21 
22-    const socket_path = res.args.@"socket-path" orelse socket_path_default;
23+    const socket_path = res.args.@"socket-path" orelse config.socket_path;
24 
25     var thread_pool = xevg.ThreadPool.init(.{});
26     defer thread_pool.deinit();
M src/detach.zig
+3, -2
 1@@ -1,13 +1,14 @@
 2 const std = @import("std");
 3 const posix = std.posix;
 4 const clap = @import("clap");
 5+const config_mod = @import("config.zig");
 6 
 7 const params = clap.parseParamsComptime(
 8     \\-s, --socket-path <str>  Path to the Unix socket file
 9     \\
10 );
11 
12-pub fn main(socket_path_default: []const u8, iter: *std.process.ArgIterator) !void {
13+pub fn main(config: config_mod.Config, iter: *std.process.ArgIterator) !void {
14     var gpa = std.heap.GeneralPurposeAllocator(.{}){};
15     defer _ = gpa.deinit();
16     const allocator = gpa.allocator();
17@@ -26,7 +27,7 @@ pub fn main(socket_path_default: []const u8, iter: *std.process.ArgIterator) !vo
18     };
19     defer res.deinit();
20 
21-    const socket_path = res.args.@"socket-path" orelse socket_path_default;
22+    const socket_path = res.args.@"socket-path" orelse config.socket_path;
23 
24     // Find the client_fd file in home directory
25     const home_dir = posix.getenv("HOME") orelse "/tmp";
M src/kill.zig
+3, -2
 1@@ -1,6 +1,7 @@
 2 const std = @import("std");
 3 const posix = std.posix;
 4 const clap = @import("clap");
 5+const config_mod = @import("config.zig");
 6 
 7 const params = clap.parseParamsComptime(
 8     \\-s, --socket-path <str>  Path to the Unix socket file
 9@@ -8,7 +9,7 @@ const params = clap.parseParamsComptime(
10     \\
11 );
12 
13-pub fn main(socket_path_default: []const u8, iter: *std.process.ArgIterator) !void {
14+pub fn main(config: config_mod.Config, iter: *std.process.ArgIterator) !void {
15     var gpa = std.heap.GeneralPurposeAllocator(.{}){};
16     defer _ = gpa.deinit();
17     const allocator = gpa.allocator();
18@@ -27,7 +28,7 @@ pub fn main(socket_path_default: []const u8, iter: *std.process.ArgIterator) !vo
19     };
20     defer res.deinit();
21 
22-    const socket_path = res.args.@"socket-path" orelse socket_path_default;
23+    const socket_path = res.args.@"socket-path" orelse config.socket_path;
24 
25     const session_name = res.positionals[0] orelse {
26         std.debug.print("Usage: zmx kill <session-name>\n", .{});
M src/list.zig
+3, -2
 1@@ -1,13 +1,14 @@
 2 const std = @import("std");
 3 const posix = std.posix;
 4 const clap = @import("clap");
 5+const config_mod = @import("config.zig");
 6 
 7 const params = clap.parseParamsComptime(
 8     \\-s, --socket-path <str>  Path to the Unix socket file
 9     \\
10 );
11 
12-pub fn main(socket_path_default: []const u8, iter: *std.process.ArgIterator) !void {
13+pub fn main(config: config_mod.Config, iter: *std.process.ArgIterator) !void {
14     var gpa = std.heap.GeneralPurposeAllocator(.{}){};
15     defer _ = gpa.deinit();
16     const allocator = gpa.allocator();
17@@ -26,7 +27,7 @@ pub fn main(socket_path_default: []const u8, iter: *std.process.ArgIterator) !vo
18     };
19     defer res.deinit();
20 
21-    const socket_path = res.args.@"socket-path" orelse socket_path_default;
22+    const socket_path = res.args.@"socket-path" orelse config.socket_path;
23 
24     const unix_addr = try std.net.Address.initUnix(socket_path);
25     const socket_fd = try posix.socket(posix.AF.UNIX, posix.SOCK.STREAM, 0);
M src/main.zig
+5, -5
 1@@ -35,10 +35,10 @@ pub fn main() !void {
 2 
 3     switch (command) {
 4         .help => try cli.help(),
 5-        .daemon => try daemon.main(config.socket_path, &iter),
 6-        .list => try list.main(config.socket_path, &iter),
 7-        .attach => try attach.main(config.socket_path, &iter),
 8-        .detach => try detach.main(config.socket_path, &iter),
 9-        .kill => try kill.main(config.socket_path, &iter),
10+        .daemon => try daemon.main(config, &iter),
11+        .list => try list.main(config, &iter),
12+        .attach => try attach.main(config, &iter),
13+        .detach => try detach.main(config, &iter),
14+        .kill => try kill.main(config, &iter),
15     }
16 }