Zigish: A shell written in pure zig

[Zigish]:


A very early WIP shell that I started to learn the new std.Io Interface. Right now it is the most bare-bones shell, i.e. it is a text-based interface to the system. What makes this a “real shell,” not just a toy a-la Tutorial - Write a Shell in C • Stephen Brennan or Forking is Cool, or: A Unix Shell in Zig, or: Dave Learns How to Fork - ratfactor is that I implemented pipes! (no offence meant to those tutorials of course, they were wonderful starting points and refrences!)

My plan is to keep working, adding IO redirection to and from files, and history/tab completion using GitHub - joachimschmidt557/linenoize: A port of linenoise to zig · GitHub.

This is a project mostly for myself, I want to eventually replace bash as my ‘daily driver’ shell.

Supported Zig versions

0.16.0
I want to keep up-to-date with the latest release, so it may or may not be compatible with master.

18 Likes

Hi there! I can see, it is very minimal yet, but I LOVE this idea! That must be a great journey, I am sure!

1 Like

Yes, ive been working on it for a combined total of maybe 10 hours, but yeah! I’ve been having a lot of fun, as well as learning ever more about *nixes and how shells actually do io redirection.

2 Likes

I always love to try new stuff, I’ll keep an eye on this project.

Also, I know that we all love the name zig, but we really should only use it for naming libraries. Other apps also don’t use the name of the programming language in the app name itself.
For a shell you have to go with something traditionally, like selfish

1 Like

Are you planning on including any command-line completion. If so, depending on the capabilities, I could adapt zigclc and zineclc to work with zigish

Really cool. Just cloned your project and gave it a try. Runs very well.

I also like it that your shell displays the exit code (I assume) of the last command by default. However, the error code only gets updated if one of your builtins is executed:

 0 $ cd /cool # try cd to non-existen dir
 254 $ pwd # error code 254, try execute external command
/home/lukeflo
 254 $ echo code # still error code of builtin cd, not 0 for successful external. run builtin echo
code 
 0 $ # back to correct exit code for builtin echo

Of course, you might be aware of this. It just was the first thing popping to my eye because I liked the standard prompt containing the exit code so much.

Beside that, great work! I’ll keep an exe on this

1 Like

I really like this idea. Are you just trying to reimplement bash or do something different? – I personally don’t care for unix style shell scripting and would love a native shell that used more c style.

Also have you checked out this tutorial on code crafters.

1 Like

Cool! Do you want to add cmdline-completion like Fish?

This is very cool! I’ve got a teeny project started like this myself, called zish, but I hardly got anywhere with it. Good luck on replacing Bash, make something good enough even I might use it! :slight_smile:

1 Like

Yes, linenoize is a zig port of the readline(3) library, so eventually i want to implement bash (or zsh) style completion.

I was not aware of that! Yes, it should show the stautus of the last command run, thank you for pointing that out.

Right now the idea is to re-implement my usual bash workflow, as I use bash already, but once I get further into it (you’ll notice there is no scripting capability currently) who knows? I think I want to follow the zen of zig, and bring it to a scripting language, but so far I don’t really know what that looks like yet.

I had not seen that, I’ll check it out, but a cursory glance makes it look like a pretty hand-holding tutorial, which I want to avoid (I don’t like overbearing tutorials).

I’ll take that under advisory, but hopefully it will be a shell that is zig-ish ;3

1 Like

Hey, I’m also working on a minimal shell in zig. I must say it’s a nice feeling going through a similar project to see how differently things were implemented. Check out mine: shellu.

I have command completion implemented, thanks to GNU readline

2 Likes

Completely understandable. I stumbled across linenoize trying to find a zig replacement, but yeah, readline is the OG in that space.

You have put a lot more work into the fundamentals for sure, I really just jumped straight into IO redirection honestly. I like what you’ve got going on, and I might steal ideas. Looks really nice!

Appreciate it! Yeah, actually I’ve been meaning to replace readline with linenoize, mainly to avoid any system dependency. That’s also why I’m not going to use Anyline, which I suggest you check out. It’s supposed to be a drop in replacement for readline, if I’m not mistaken, purely written in zig.

1 Like

Thanks for posting this. Your project inspired me to add gitlab support to my hew cli tool. I can build/install your project from source on linux/macos via:

sh -c "$(curl -fSL https://gethew.github.io/sh)"
hew install gitlab:zigish/zigish
4 Likes