Show HN: Repo: Little droplets of Zig code to familiarize with by example

4 months ago 12

Ziglets Logo

Ziglets is a collection of simple Zig CLI applications, designed as educational examples for learning the Zig programming language.

Zig License GitHub Stars Latest Release CI Release

The goal of this project is to provide minimal, easy-to-read code samples for common CLI patterns in Zig. Each command is implemented in its own file and demonstrates basic Zig features such as argument parsing, modularity, and interaction with the standard library.

To build the project, make sure you have Zig installed (tested with Zig 0.14.0):

The resulting binary will be located in zig-out/bin/ziglets.

Pre-built binaries are available for multiple platforms and architectures. Visit the Releases page to download:

  • Linux: x86_64 and ARM64 (both glibc and musl)
  • Windows: x86_64 and ARM64 (GNU and MSVC toolchains)
  • macOS: x86_64 (Intel) and ARM64 (Apple Silicon)
  • Automated releases are created when tags following semantic versioning (v*.*.*) are pushed to the main branch
  • All binaries include SHA256 checksums for verification
  • Cross-platform builds are tested on every release

Run the CLI with:

zig-out/bin/ziglets <command> [args...]
  • hello — Prints "Hello, World!"
  • goodbye — Prints "Goodbye, World!"
  • echo ... — Runs the system echo command with the provided arguments
  • guess — Play a "Guess the number" game
  • writer ... — Save a string to file.txt and display its content
  • base64 ... — Encode text to Base64
  • pgen ... — Generate a random password
  • calculator — Interactive calculator (press keys, Q to exit)
  • touch ... — Create empty file(s)
  • factorial <number> [num_threads] — Calculate the factorial of a number using multiple threads
  • help — Shows the help page
zig-out/bin/ziglets hello zig-out/bin/ziglets echo Zig is fun! zig-out/bin/ziglets guess zig-out/bin/ziglets writer Hello from Zig! zig-out/bin/ziglets base64 "Hello, Base64!" zig-out/bin/ziglets pgen -l 16 -aA1& zig-out/bin/ziglets calculator zig-out/bin/ziglets touch file.txt zig-out/bin/ziglets factorial 20 4

Each command is implemented in its own Zig file and imported in main.zig.
You can explore the source code in the src/ directory to see how each feature is implemented.

  • The file file.txt used by the writer command is ignored by git (see .gitignore).
Read Entire Article