I customised my ZSH prompt with Zig

I’ve been having a lot of fun learning Zig doing Advent of Code puzzles.

This is my first little utility project Zigbar — suggestion for better name welcome! It generates a prompt for ZSH showing the current project git branch, language, etc.

I blogged a small write-up of how it works but I don’t go into the Zig code itself.

I’m still discovering the standard library and best Zig coding practices. I want to avoid learning bad habits, so criticism is welcome!

12 Likes

I spent some time working on my build.zig to add two more steps:

  1. generate tarball
  2. sign tarball with minisign

I run this build in a GitHub action to generate releases.

I then wrote a self-update command so that I can run zigbar update which fetches, verifies, and updates the binary. (I’m embedding the minisign public key during the build process.)

I like that the JSON parser in the Zig std lib allows partial schema, e.g:

const Release = struct {
    tag_name: []const u8,
    assets: []struct {
        name: []const u8,
        size: usize,
        browser_download_url: []const u8,
    },
};
var releases = try std.json.parseFromSlice(
    []Release,
    allocator,
    result.stdout,
    .{ .ignore_unknown_fields = true },
);

The GitHub API response has many fields I don’t need to care about.

I’ve written a little more on my blog.

Anyway, thought that might be useful for anyone interested in a secure build, release, update process via GitHub!

3 Likes

Nice! I was thinking of adding a signed release workflow to Liza, but I actually found it easier to update Zig executable projects by simply git pulling latest changes, building with zig build exe and already having their installed executables (zig-out/bin/exe) in $PATH.

Building from source does require zig, but downloading binaries requires a dependency as well – minisign. It’s a choice, but for small enough projects building from source is also viable.

2 Likes

I’m using zig-minisign library for verification, so it’s a dependency that can be compiled in without needed the full minisign for updating which is nice.

I do actually just use git to distribute many of my projects, especially since I use JavaScript for most things!

1 Like

Cool project!

zshbar does not appear to be taken. That’s better: it isn’t a bar for Zig, it’s a bar for ZSH.

Especially in the early, heady stage of learning a new language, people often want to tag their projects with the name of that language. This is almost never a good idea. Unless Zig, the language, is the topic of the project, it doesn’t need to be in the name, and should not be.

Edit: zzbar, perhaps. Lot of options here.

3 Likes

Thanks, good point. I like zzbar, I’m not to fussed over a perfect name but it makes sense to remove “zig”. I’ll give it some thought.

2 Likes