const std = @import("std"); const stdout_file = std.io.getStdOut().writer(); var bw = std.io.bufferedWriter(stdout_file); const stdout = bw.writer(); pub fn main() !u8 { const action = std.os.getenv("ACTION") orelse return error.MissingAction; if (std.mem.eql(u8, action, "get")) { try get(std.os.getenv("URL") orelse return error.MissingUrl); return 0; } else { try stdout.print("error unexpected action {s}\n", .{action}); try bw.flush(); return 1; } } fn get(url: []const u8) !void { try stdout.print("title {s}\n", .{url}); try stdout.print("add_tab\n", .{}); if (!std.mem.eql(u8, url, "/")) { try stdout.print("title Go to parent directory\n", .{}); try stdout.print("url ..\n", .{}); try stdout.print("thumbnail_url folder.png\n", .{}); try stdout.print("thumbnail_size 32x32\n", .{}); try stdout.print("add_body_item\n", .{}); } var dirIt = try std.fs.cwd().openIterableDir(url, .{ .no_follow = true }); defer dirIt.close(); var pathBuf: [std.fs.MAX_PATH_BYTES]u8 = undefined; var it = dirIt.iterate(); while (try it.next()) |*entry| { var fba = std.heap.FixedBufferAllocator.init(&pathBuf); var allocator = fba.allocator(); const fullFilepath = try std.fs.path.join(allocator, &[_][]const u8{ url, entry.name }); try stdout.print("title {s}\n", .{fullFilepath}); try stdout.print("url {s}\n", .{fullFilepath}); if (entry.kind == .directory) { try stdout.print("thumbnail_url folder.png\n", .{}); } else { try stdout.print("thumbnail_url file.png\n", .{}); } try stdout.print("thumbnail_size 32x32\n", .{}); try stdout.print("add_body_item\n", .{}); } try bw.flush(); }