about summary refs log tree commit diff
path: root/src/exe.zig
blob: ef38a673cc58d8b51af4375ac715a09df397d212 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const std = @import("std");

const log = std.log.scoped(.exe);
const Context = @import("main.zig").Context;
const fs = @import("fs.zig");

pub fn run_pandoc(ctx: *Context) !void {
    ctx.progress_start("Processing markdown files");
    defer ctx.progress_end();

    for (ctx.markdown.items) |page| {
        const targetpath = try fs.replace_extension(ctx.allocator(), page, "md");
        defer ctx.allocator().free(targetpath);

        const f = try fs.FileSwapper.createAt(ctx.allocator(), targetpath);
        defer f.close();

        try run(ctx, &.{ "notify-send", "hi", page });
    }
    // @ echo "<!-- Generated file, you may edit and discard $< :) -->" >$@
    // $(PANDOC) -fmarkdown+wikilinks_title_after_pipe+autolink_bare_uris -thtml5 --lua-filter=$(PANDOC_PREPROC) --strip-comments $< >>$@
}

pub fn run(ctx: *Context, argv: []const []const u8) !void {
    const command = try std.mem.join(ctx.allocator(), " ", argv);
    defer ctx.allocator().free(command);
    const label = try std.fmt.allocPrint(ctx.allocator(), "running {s}", .{command});
    defer ctx.allocator().free(label);

    ctx.progress_start(label);
    defer ctx.progress_end();

    const result = try std.process.Child.run(.{
        .argv = argv,
        .allocator = std.heap.page_allocator,
        .progress_node = ctx.progress_nodes.getLast(),
    });
    _ = result;
}