Allow newlines inside `$` command
Allowing newlines inside $ might be nice for long commands. For example:
await $`command
--flag-one
--flag-two
--flag-three
...
--lots-of-flags`
At the moment, arguments are delimited by spaces. We should use \s instead.
https://github.com/sindresorhus/execa/blob/8ef8e90e13dc2ab8cc69ed360ba3485e464d39f0/lib/command.js#L26
Injections are not possible with $ since dynamic values require using ${...}, in which case \s will not be considered delimiters.
This should apply to execaCommand() too, which uses the same underlying logic. execaCommand() is meant for passing trusted dynamic input as is, for example for a REPL. Allowing newlines for a REPL is useful too. If the input is not trusted, execa() or $ should be used instead.
What do you think @sindresorhus?
I guess we could, but maybe we should keep it open a bit more to see if people can come up with any issues with it. It's not an important feature, but it will be harder to take it away later on.
The only downside I see is that you can no longer copy the command and run it in a real shell for debugging.
Good point about copying. One would need to add trailing backslashes, or join all lines into one before copying.
Let's keep this on the back burner and wait. :+1:
I like the idea 👍 I currently use arrays in $ expressions to clean up long commands:
await $`command ${[
'--flag-one',
'--flag-two',
'--flag-three',
'...',
'--lots-of-flags',
]}
`
I just came across this: someone also asked for this feature with zx and it got 6 thumbs ups. That's their 6th most upvoted issue out of 63. There are some good points in favor of it being made. The main cons seem to be zx-specific (shell quoting-related) and does not impact Execa.
@sindresorhus What are your thoughts using the following issue from zx? Especially the fact that many users seem to want that feature and zx is currently missing it.
Alright, lets do it.