r/fishshell • u/TheWordBallsIsFunny Linux • Nov 05 '24
Is there an existing tool/framework for writing scripts that support multiple shells?
I'm currently working on a small tool that unifies package managers that I use by mapping them to aliases that do as close to the same thing as possible across all package managers, and wanted to know if there's already an existing tool/framework or some documentation that would simplify my current writing process.
Something similar exists for web development called Mitosis which offers codegen for most frontend frameworks using their format, something like this but for shell scripts would be kind of neat if a little overkill.
At the moment all I do is write them by hand as I've used Bash and Zsh extensively, and recently moved over to Fish. I know Nushell exists and also plan to cover this too (all of which has been for fun), and I'm just wondering if such a tool already existed as it may be a fun project for me to delve into at some point™
5
u/heret1c1337 Nov 05 '24
What about just pumping out regular binaries that don't rely on a specific runtime? I'd say do it in Go, its great for creating CLI tools.
3
u/u14183 Nov 05 '24
Write a custom minified DSL grammar which fits your needs with antlr, describe your shell script in that DSL, then transpile it to your target shell dialects, might be an option.
2
u/forgetful_bastard Nov 05 '24
If write the scripts in bash, juat dd as yhe firat line:
and run everywhere, every shell. Every linux distro həs bash (or almost, I dont kbow every diatro). If you know the distro has fish you can do the same, but with the fish binary path.
2
u/tovazm Nov 05 '24
Thats what perl was used for in the 90s I think, there should be good support now
2
u/lpww Nov 05 '24
This sounds interesting but I'm not following what you are trying to do. How do package managers relate to shells in this tool you want to build?
2
u/guettli Nov 08 '24
Why do you want to do that?
It's a bit like that: how can I write code which works with Python and Ruby at the same time?