[try Beta version]
Not logged in

 
trying to make a zsh-like shell for windows

Nov 6, 2021 at 10:17pm
hi, i'm trying to make a zsh-like shell for windows, but i'm having some trouble to do command parsing, pipe handling, etc on windows because every tutorial i found on the internet only works for linux, and i want to do the command parsing part first before the rest.
is there any way to do at least the command parsing part on windows? here's my code:
https://pastebin.com/nSDkZ9D2
Nov 6, 2021 at 11:26pm
You may want to consider handling each keypress interactively to support command completion. You'll need to use platform specific features for this, plus wide character support.
Nov 7, 2021 at 12:17am
yeah.
Nov 7, 2021 at 12:24am
something i could do is to use the zsh source code as the base for my code, instead of trying to convert the code to windows.
well, technically i'm converting the code to windows, but you got the point.
Last edited on Nov 7, 2021 at 12:42am
Nov 7, 2021 at 1:37am
nevermind, i'm too dumb for this at the moment. maybe in the future i'll make something way better than that.
Nov 7, 2021 at 1:39am
well, if i continue acting like that i'll not manage to make my own operating system in assembly, so i should work ground up.
Nov 7, 2021 at 1:48am
Cygwin has a zshell, and I think most if not all of their source code is out there on the web. Could study it but its probably a complicated port of unix source code.
Nov 7, 2021 at 2:19pm
yeah, i saw.
Nov 7, 2021 at 4:35pm
The cygwin port won't help, it's probably just the Linux code compiled against the cygwin runtime. So the code won't need to be ported.

When all this port to Windows business started, GNU tools were rewritten for Windows and ran natively. There was the MKS Toolkit that did what Cygwin does, present a Unix layer for Windows. But that was a commercial product (money, licence, ...). Redhat worked on cygwin, and the rest is history. Most Unix apps now run on Windows under some kind of Unix emulation, like cygwin.

You're proposing writing a native zsh. It's a daunting task. You could start with your own Bourne Shell, and use the experience gained from that for your zsh. It's not a trivial task.
Last edited on Nov 7, 2021 at 11:45pm
Nov 7, 2021 at 4:40pm
yeah, this is what i was thinking about to do, i would first write a basic sh-like shell and then make the zsh-like shell.
Nov 7, 2021 at 4:42pm
i could start by using the debian almquist shell source, and then, in the future, use the zsh source code as the base, so it would look like a bit mixed between two different shells.
Nov 8, 2021 at 9:16am
It's probably best to start from scratch.

There's lots of stuff in a shell, much of which you're probably not aware of right now. I suggest you start with one feature at a time, starting with the ability to start a program. This way you'll become more knowledgeable about all shells.

You'll also learn about differences between fundamental things in both platforms that you'd not have considered before; like controlling terminals in Unix, and controlling consoles in Windows, differences in process creation and management, IPC, security, ...

It's not a waste of time, even if you don't finish it.
Last edited on Nov 8, 2021 at 9:20am
Nov 8, 2021 at 7:07pm
i agree.
Nov 8, 2021 at 9:02pm
My best suggestion is to learn how to write a parser. YACC (or BISON if using GNU) is a great tool. Very useful in writing command parsers, languages and interpreters.

At the simplest level a parser takes input (text) tokens and converts them to "productions". A production is a combination of one or more tokens that represents an element of a command or language. Productions are combined and reduced until the entire input has been processed.

YACC can be daunting at first, but well worth the learning curve. It helps if you understand Backus-Naur Form (BNF).
https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form

Command shells are relatively easy if you can specify the BNF for them, run the BNF through YACC and then just write the code for the productions.
Last edited on Nov 8, 2021 at 9:06pm
Nov 11, 2021 at 1:18am
yeah.
Topic archived. No new replies allowed.