~gpanders/wk

6cfafe1302c9469f2725eeb57a52102c7d5c2705 — Greg Anders 8 months ago cb59870
Clean up zettel dir discovery

The chained if statement accomplishes the same thing, but has fewer
braces and no `break :blk` statements.
1 files changed, 9 insertions(+), 11 deletions(-)

M src/main.zig
M src/main.zig => src/main.zig +9 -11
@@ 17,17 17,15 @@ pub fn main() anyerror!void {
        return;
    }

    const dir = blk: {
        if (std.os.getenv("ZETTEL_DIR")) |dir| {
            break :blk try std.mem.dupe(allocator, u8, dir);
        } else if (std.os.getenv("XDG_DATA_HOME")) |xdg_data_home| {
            break :blk try std.fs.path.join(allocator, &[_][]const u8{ xdg_data_home, "zet" });
        } else if (std.os.getenv("HOME")) |home| {
            break :blk try std.fs.path.join(allocator, &[_][]const u8{ home, ".local", "share", "zet" });
        } else {
            unreachable; // $HOME should always be defined
        }
    };
    const dir = if (std.os.getenv("ZETTEL_DIR")) |dir|
        try std.mem.dupe(allocator, u8, dir)
    else if (std.os.getenv("XDG_DATA_HOME")) |xdg_data_home|
        try std.fs.path.join(allocator, &[_][]const u8{ xdg_data_home, "zet" })
    else if (std.os.getenv("HOME")) |home|
        try std.fs.path.join(allocator, &[_][]const u8{ home, ".local", "share", "zet" })
    else
        unreachable; // $HOME should always be defined

    defer allocator.free(dir);

    try std.fs.cwd().makePath(dir);