diff options
| author | Gabriel Schneider <[email protected]> | 2026-07-08 05:35:09 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-01 15:02:07 -0300 |
| commit | 146944accb5852c548e25c7194b2865531e67cbb (patch) | |
| tree | 532be12c0e5b4c8ff8bfafc6712f7011fd98784b /src/main.zig | |
| parent | 2826704c7f829b5b5375ed2bf7414b455d3b0735 (diff) | |
| download | pardes-146944accb5852c548e25c7194b2865531e67cbb.tar.gz pardes-146944accb5852c548e25c7194b2865531e67cbb.zip | |
argv positionals: bare pardes boots the shell pane in tty mode, a FILE arg (file:LINE works) opens it focused in the left column with a greeting terminal on the launch dir at right, a DIRECTORY arg chdirs so shells spawn there. New argv.snap; boot/restore.snap pin -n 1 to keep the classic boot.
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/main.zig b/src/main.zig index 5275ea28..2e75de3d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -39,7 +39,11 @@ pub const debug = if (is_emscripten) struct {} else struct { }; const help_text = - \\Usage: pardes [options] + \\Usage: pardes [options] [file|dir] + \\ + \\With no arguments the shell pane starts in tty mode. A FILE argument + \\(optionally file:LINE) opens it focused beside a terminal on the launch + \\directory; a DIRECTORY argument becomes the cwd shells spawn in. \\ \\Options: \\ --tty start as one shell pane already in tty mode @@ -77,7 +81,10 @@ fn webMain() !void { fn nativeMain(init: std.process.Init) !void { var opts: pardes.Options = .{}; - const args = try init.minimal.args.toSlice(init.arena.allocator()); + const arena = init.arena.allocator(); + const args = try init.minimal.args.toSlice(arena); + if (args.len == 1) opts.tty_only = true; // bare `pardes` boots straight into tty mode + var positional = false; var i: usize = 1; while (i < args.len) : (i += 1) { const a = args[i]; @@ -100,6 +107,23 @@ fn nativeMain(init: std.process.Init) !void { } else if (std.mem.eql(u8, a, "-h") or std.mem.eql(u8, a, "--help")) { try std.Io.File.stdout().writeStreamingAll(init.io, help_text); return; + } else if (a.len > 0 and a[0] != '-' and !positional) { + // one positional: a directory becomes the cwd shells spawn in + // (chdir succeeds only on dirs); anything else resolves as a file + positional = true; + if (std.c.chdir(a.ptr) != 0) { + var cwdbuf: [4096]u8 = undefined; + const cwd = std.c.getcwd(&cwdbuf, cwdbuf.len) orelse return error.BadArgs; + var realbuf: [4096]u8 = undefined; + switch (@import("look.zig").resolve(a, std.mem.span(@as([*:0]u8, @ptrCast(cwd))), &realbuf)) { + .file => |t| { + opts.file = try arena.dupe(u8, t.path); + opts.file_line = t.line; + }, + .image => |t| opts.file = try arena.dupe(u8, t.path), + else => return error.BadArgs, + } + } } else { return error.BadArgs; } |
