ngs-lang / ngs

Next Generation Shell (NGS)
https://ngs-lang.org/
GNU General Public License v3.0
1.4k stars 43 forks source link

Intuitive syntax for calling external programs preserving output #649

Open mturilin opened 11 months ago

mturilin commented 11 months ago

Note: This is a minor nitpick for otherwise an amazing system.

Role: As a developer, I want to use NGS to create scripts that stitch together external commands, like in shell scripts.

Problem: $(top_level:: looks less intuitive than plan bash.

Example 1: NGS

{
  for container in containers {
    $(top_level::  ./launch_container.sh ${container})
  }
}

You can see that $(top_level:: visually distracts from the command itself.

Bash:

for i in {1..3}
do
  ./launch_container.sh ${containers[$i]}
done

I think this syntax looks much cleaner.

mturilin commented 11 months ago

As discussed in the chat, a single $ option could be much nicer:

{
  for container in containers {
    $ ./launch_container.sh ${container}
  }
}
ilyash-b commented 11 months ago

Having some reservations (it would already be implemented otherwise). Thinking here:

This is line oriented syntax: from $ and until end of line. Not particularly fond of it. Can't have multiple commands on the same line while you can have other syntax elements separated by ; on the same line. $ ...; ... would look weird.

$ ... is kind of counterpart of $(...). Since there is %(...) syntax (for defining a command without running it), one might expect % ... syntax as well, which I was not thinking implementing.

ilyash-b commented 10 months ago

Still thinking about syntax and not finding anything that would be "oh, that's right!".

Any ideas on that front @mturilin ?

mturilin commented 9 months ago

I was also looking at xonsh and they have nice syntax for "uncaptured subprocess": https://xon.sh/tutorial.html#uncaptured-subprocess-with-and

My previous example would look like this:

{
  for container in containers {
    $[./launch_container.sh ${container}]
  }
}
ilyash-b commented 9 months ago

Sounds like a candidate. Need to think a bit about how it fits with the rest.