地圖 (Jido) is a lightweight Unix TUI file explorer designed for speed and simplicity.
1const std = @import("std");
2
3/// Callers owns memory returned.
4pub fn getGitBranch(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 {
5 var file = try dir.openFile(".git/HEAD", .{});
6 defer file.close();
7
8 var buf: [1024]u8 = undefined;
9 const bytes = try file.readAll(&buf);
10 if (bytes == 0) return null;
11
12 const preamble = "ref: refs/heads/";
13
14 return try alloc.dupe(u8, buf[preamble.len..]);
15}