diff options
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; } |
