Replies: 4 comments 8 replies
-
A workaround for annoying |
Beta Was this translation helpful? Give feedback.
-
@antongolub By moving it to a discussion, are you saying that this is a bad idea and that you won't accept PRs to add this functionality? The original intent of the issue was a code feature request, not to ask a question in a discussion format. |
Beta Was this translation helpful? Give feedback.
-
I have been writing some
s`foo` Is equivalent to: await $`foo`
a`foo` Is equivalent to: $`foo`
Is equivalent to: (async $`foo`).toString() The combination of these 3 things would allow us to create extremely concise scripts. |
Beta Was this translation helpful? Give feedback.
-
Another thing: #91 is spot on, having to do |
Beta Was this translation helpful? Give feedback.
-
Improvement 1 - Automatic Await
I predict that most uses of
zx
in the wild are people rewriting their Bash scripts into JavaScript/TypeScript.For example, I imagine a common script might look something like this:
It strikes me that this could be simplified.
zx
could automaticallyawait
every$
invocation. If it did that, then the code could be simplified to this:Much better! However, I presume the downside to this approach is that we lose the ability to do background tasks. For example, the previous code might want to be written like:
So that's a problem. One idea is to parse the command for the
&
symbol, which would disable the awaiting behavior, like this:I chose the
&
symbol because that is the background execution operator in bash. In this setup, we get the best of both worlds.Of course, this would be a breaking change and might disrupt the ecosystem. So, another idea is to add an option:
Yet another idea/approach would be to use a separate symbol other than a dollar sign as an indication of "run a command like $, but always await it automatically". For example:
(Underscore and dollar sign are the only symbols that are valid as function names, so here I'll somewhat-arbitrarily choose underscore since dollar sign is taken.)
Improvement 2 - Automatic Output
It looks like this is a common pattern:
It strikes me that this could be abstracted further. Similar to my previous suggestion, it could be possible to add a symbol that is similar to
$
, but combines the await and toString parts. As an example, I'll arbitrarily choose theo
letter, which is short for "output":Another option is to use an underscore instead of
o
. Regardless, this would be a nice abstraction.Beta Was this translation helpful? Give feedback.
All reactions