~gpanders/wk

20be22bcd9adf5159a4c4993bbb5ddfa84f7dd80 — Greg Anders a month ago 55fa3e6
Add 'inbox' subcommand
2 files changed, 39 insertions(+), 1 deletions(-)

M src/cmd.zig
A src/cmd/inbox.zig
M src/cmd.zig => src/cmd.zig +2 -1
@@ 8,12 8,13 @@ const ChildProcess = std.ChildProcess;

const commands = .{
    @import("cmd/backlinks.zig").cmd,
    @import("cmd/inbox.zig").cmd,
    @import("cmd/list.zig").cmd,
    @import("cmd/new.zig").cmd,
    @import("cmd/open.zig").cmd,
    @import("cmd/preview.zig").cmd,
    @import("cmd/sync.zig").cmd,
    @import("cmd/show.zig").cmd,
    @import("cmd/sync.zig").cmd,
    @import("cmd/tags.zig").cmd,
};


A src/cmd/inbox.zig => src/cmd/inbox.zig +37 -0
@@ 0,0 1,37 @@
const std = @import("std");
const ascii = std.ascii;
const fmt = std.fmt;
const mem = std.mem;
const os = std.os;
const warn = std.debug.warn;

const Command = @import("../cmd.zig").Command;
const Zettel = @import("../zettel.zig").Zettel;

pub const cmd = Command{
    .name = "inbox",
    .aliases = &[_][]const u8{ "i", "in" },
    .usage = "in|inbox",
    .desc = "Open inbox in your editor",
    .run = run,
};

pub fn run(allocator: *mem.Allocator, args: ?[]const []const u8) Command.Error!void {
    const argv = &[_][]const u8{
        os.getenv("EDITOR") orelse "vi",
        "inbox.md",
    };

    var proc = try std.ChildProcess.init(argv, allocator);
    defer proc.deinit();

    const term = try proc.spawnAndWait();
    switch (term) {
        .Exited => {},
        else => {
            warn("The following command terminated unexpectedly:\n", .{});
            for (argv) |arg| warn("{} ", .{arg});
            return error.CommandFailed;
        },
    }
}