diff options
Diffstat (limited to 'src/builtins.zig')
| -rw-r--r-- | src/builtins.zig | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/builtins.zig b/src/builtins.zig index ed6ac467..129dd659 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1142,21 +1142,21 @@ pub const Get = struct { pub fn run(c: Ctx) void { const ctl = @import("ninep/ctl.zig"); const f = if (c.pane.file) |*file| file else return c.p.reportFailure(c.id, "Get: only a file pane takes it"); + const typed = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); // A directory pane: the directory read again (Dir.zig), as acme's - // Get is in a directory window. - if (f.listing != null) return panes.Dir.show(c.p, c.id, c.id); + // Get is in a directory window; a file is a Look's from there. + if (f.listing != null) { + if (typed.len > 0) return c.p.reportFailure(c.id, "Get: a directory pane reads its directory; a Look at the file opens it"); + return panes.Dir.show(c.p, c.id, c.id); + } if (!panes.Output.fileTraits(f.output).saves) return c.p.reportFailure(c.id, "Get: only a file pane takes it"); if (ctl.getRefused(c.p, c.pane, "Get")) |said| return c.p.reportFailure(c.id, said); - const typed = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); - if (typed.len > 0) { - var home_buf: [4096]u8 = undefined; - const full = std.fs.path.resolvePosix(c.p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), @import("fs.zig").expandHome(typed, &home_buf) }) catch return; - @import("ninep/pane.zig").nameBuffer(c.p, c.id, full, false) catch return c.p.reportFailure(c.id, "Get: invalid file name"); - } var failed: anyerror = error.Unexpected; - if (ctl.get(c.p, c.pane, &failed) != 0) { + var home_buf: [4096]u8 = undefined; + const path = if (typed.len == 0) c.pane.file.?.path else std.fs.path.resolvePosix(c.p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), @import("fs.zig").expandHome(typed, &home_buf) }) catch return; + const errno = if (typed.len == 0) ctl.get(c.p, c.pane, &failed) else ctl.getFile(c.p, c.pane, path, &failed); + if (errno != 0) { var said: [320]u8 = undefined; - const path = c.pane.file.?.path; c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Get: {s}: {s}", .{ path[0..@min(path.len, 256)], if (failed == error.FileNotFound) "no such file" else "cannot be read" }) catch "Get: cannot be read"); } } |
