nushell: Pasting multi-line command (with backslash) doesn't work

Related problem

When finding command line examples online, I find that it’s fairly common to split these up into multiple lines for readability. Usually, a backslash character is used to do this split, like:

curl -o out.json \
  -H 'Authorization: Bearer some-token' \
  http://www.example.com/some-path

I can’t get this to work when trying nushell on my mac.

Describe the solution you’d like

These examples using backslash as line separator are so common that nushell should support it.

Describe alternatives you’ve considered

I just tried googling “nushell multiline command” and the like to see whether there was some config or whatever that I should have set to get it to work. Didn’t find anything 🤷🏻

Additional context and details

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 8
  • Comments: 22 (5 by maintainers)

Most upvoted comments

I’d rather not have a fundamental shell functionality, like line continuation, only work on *nix platforms. I’d prefer to do something that works on all platforms the same way, such as using an alternate line continuation character like backtick as pwsh does.

I didn’t get that at all from this thread. lol. it sounded to me like you and jt wanted to implement a \ line continuation character as opt-in in *nix only. that’s what I was objecting to. If you’re talking only about pasting and reformatting into the proper nushell line continuation format, then i’d support it, given what you’ve described just now in your ‘more generic’ proposal. i think having a config point is also good. thanks for explaining this so i can understand it. 😃

I see. It looks like I might have failed to convey the underlying intention with this issue… I’m happy to hear that there is a way to construct a multiline command in nushell (which I hadn’t realized) 👍🏻

But my issue is that copying and pasting “commands using backslash as a multiline separator” from the plethora of articles and websites already present on the internet does not work in nushell, while it does work in bash, zsh and fish.

I’m new to nushell, and I really like some parts of it, but I’m trying to make you aware of “reasons to stay with zsh”, which I’ve been using for the past couple of years, and things like this are among them.

I’d be curious to know whether there’s a technical or philosophical reason why nushell can’t support pasting the curl command snippet from my description at the top? Or is it just something that “hasn’t been implemented yet”? If the latter is the case, it could possibly be an interesting thing for a Rust-novice like me to try and implement?

If one command is wrapped in (...), it no longer produces a stream. Therefore, this example will fail:

def test_exit_code [] {
    let res = do {
        (nu -c "exit 2")
    } | complete
    print $res
}

…with the complain complete only works on external streams

My bad, bracketed paste does (disregardig #9944). I now use it in my project.

As the \ is a valid path in Nushell, it can’t be the continuation character. We support multiline commands by surrounding with (). With that, I believe this has been fixed.

@torarvid - one issue with the traditional line continuation character (\) is that this is a valid path name in Windows. Nushell, whenever possible, tries to always be compatible across platforms, including Windows. If we supported the \ as a continuation character, we’d need to do it in a way that this also works with Windows paths.

The backslash character \ is not a line continuation character in nushell. At the moment the only line continuation characters that are supported are [, (, and { while they’re being used in nushell syntax.