Amber the programming language compiled to Bash/Ksh/Zsh
amber-lang.com
amber-lang.com
https://docs.amber-lang.com/0.6.0-alpha/basic_syntax/importi...
it seems like automatic `--help` + named args is still not a thing? if it were, I'd be all over this
#!/usr/bin/tcc -run
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Hello from C!\n");
for (int i = 1; i < argc; ++i)
printf("argument %d: %s\n", i, argv[i]);
return 0;
}
And ready is your cscript :) $ chmod u+x cscript && ./cscript hello world
Hello from C!
argument 1: hello
argument 2: world
(I can't even articulate why I love it so much that this works) $ cat bscript.sh && echo "---" && ./bscript.sh
#!/usr/bin/bash
cd testdir/
ls
---
dummyfile
in C you can change dir easily via `chdir()`[1] $ cat cscript && echo "---" && ./cscript
#!/usr/bin/tcc -run
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
if (chdir("testdir") == -1) {
perror("chdir");
return EXIT_FAILURE;
}
execlp("ls", "ls", (char *)NULL);
perror("execlp");
return EXIT_FAILURE;
}
---
dummyfile
[1] https://www.man7.org/linux/man-pages/man2/chdir.2.htmlIf you meant somehow changing the parent shell's directory an ordinary bash script doesn't do that either
Or did you mean change the directory of the calling shell (in which case, executable shell scripts written in Bash and friends can’t do that either).
So these days I almost exclusively use Go wherever bash and friends aren't enough. Compile to Linux x86 & ARM and Darwin ARM, or just "go run" if it's simple enough.
Try it out :)
uv init uv add XXX uv run main.py
( You can pin python versions and auto install them etc )
Side note: the image of project founder cosplaying as Steve Jobs on front page had me dying.
If your script is complex enough to need a higher level language you might as well just switch to python
As said there are use cases where you want to use only bash because you can't install scripting languages with their dependences as example.
As usual there is a tool for any user cases and Amber resolves some of them :-)
Hmm...
2. Support Fish too. Having one language that can generate zsh (macOS default), Fish (power users default), and bash would be really nice!
About Fish we are planning to support more bash subset but we aren't so much in the team to focus in everything. Right now the priority is to adds more stuff to the language in a way we can stabilize it and implement the other "output" target later.
About the production ready the Bash code is tested, shellchecked tested (we are not at 100% yet) and works but is an alpha because we are working in the syntax.
Right now we check the bash output with Shellcheck but we are not yet full valid and we test it for performances.
About security right now we are just avoiding evail and this kind of things, we are focusing right now on stabilizing the language itself.
And I can say only Thanks :-D
Second, just why?
As I said in other similar answers, there are some context where you can't use other languages or install packages but bash is everywhere (as example).
Literally the worst of both worlds.
Yes, Bash or any shell is a very complex and utterly environment dependent language to approach with all due care for security and compatibility, yet hence the lack of wrapper that may not even be aware of these crucial cases at all.
That said, this should just be a shell itself and not something that generates into other shell dialects. Otherwise, why not use Ruby or something like it that has actual expressive power?
I'm guessing the advantage here would be that the compiled "bytecode" (the resulting bash) can be distributed to systems that would then not need to have Amber installed. (And vs. a real binary from, e.g., Go/Rust/etc., it isn't tied to the platform, either.)
Vs. a Ruby script would require Ruby as a run-time dependency; Amber here is effectively a compile-time dependency.
Python 3 is available basically everywhere these days though, so I think there's still a lot of merit to just using a higher level language like you suggest. Even Ruby, while not available out of the box, is not exactly hard to get on most OSes.
It took my quite a while to get used to all the verbose method names, but it actually makes it pretty readable by default.
There are other communities where movement in the language came from outside tooling that built extensions on top of the language, such as Sass or TypeScript.
On the other hand, we're at a point for a binary language (or standard / framework) that one AI/LLM creates and another one validates.
What are we missing?
If you know of a language that is perfect for all our needs today and tomorrow, please guide us to it.
> What are we missing?
Major concerns would be i) trust in the tooling, ii) quality and accountability, iii) future investment in competent engineering.
This is not something we're advocating, instead talking the reality from observing across the industry.