Recently, I discovered lsr. It’s ls implementation, writing in Zig with a twist. It uses io_uring to make system calls. That means a faster and more efficient program.
As I’ve written a small Nix package for lsr, it replaced eza as my system ls implementation. New projects are cool; you more often than not can understand the code and contribute.
The first issue was that the input argument could only be a directory; otherwise, you get an error message. Though the author fixed it quickly.
Then I found another issue when sorting files by name. You might think there’s nothing special about sorting; every programming language provides means to sort. Turns out humans expect natural sorting from these kinds of programs.
file1
file10
file3
Does it seem off? But that is the result of sorting by plainly comparing each character, without any smartness. I’ve never noticed before, but all ls implementations sort file names as we humans expect them to!
Next stop is to see what does eza use to sort. They have a dependency on natord, and natord took inspiration from https://github.com/sourcefrog/natsort. Though, looking at the nested match expressions, I realized that C implementation will be easier to port.
You can find my Zig port here https://codeberg.org/knightpp/natural-ordering-zig.