New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It doesn't seem possible to have multi-line commands in .fish files #347

Closed
Soares opened this Issue Oct 16, 2012 · 7 comments

Comments

Projects
None yet
4 participants
@Soares
Contributor

Soares commented Oct 16, 2012

I'm not sure if this is a bug, a missing feature, or a design decision. If the latter, close away.

Escaped newlines (i.e. lines ending with ) don't seem to work in my config.fish file. I couldn't find another way to do multi-line strings. It's not an essential feature, but some of us like to have 80-character-max scripts, especially on machines that we ssh into with frequency.

Some commands in particular get long really quickly, especially if you're slicing-and-dicing output with a bunch of cut, sed, grep, and tr commands. Jamming these all into one line makes them hard to read. I'd love to at least be able to line break right before a pipe.

@ridiculousfish

This comment has been minimized.

Show comment
Hide comment
@ridiculousfish

ridiculousfish Nov 21, 2012

Member

The backslash at the end of a line allows you to edit multiline commands. What it does not do is join commands, i.e. this:

echo foo\
bar

is the same as echo foo; bar.

I can think of no reason to prefer this behavior over traditional shell behavior, which would produce echo foobar.

Member

ridiculousfish commented Nov 21, 2012

The backslash at the end of a line allows you to edit multiline commands. What it does not do is join commands, i.e. this:

echo foo\
bar

is the same as echo foo; bar.

I can think of no reason to prefer this behavior over traditional shell behavior, which would produce echo foobar.

@Soares

This comment has been minimized.

Show comment
Hide comment
@Soares

Soares Nov 22, 2012

Contributor

This is great except for when you have significantly long sub commands. Imagine, for example:

(grep "some long piece of text" /some/long/directory | tr -d "FLAG" | cut -c '/' -f 3 | ...)

This can quickly exceed 80 characters. This problem is exacerbated by #159, which rewards keeping text out of fish variables for as long as possible, though it could theoretically happen any time you are trying to run a subcommand with enough arguments.

Another acceptable solution would be to allow line breaking at or before a pipe. Alternatively fish could allow multi-line command substitutions (python sets a good precedent for whitespace in parenthesis). Regardless, I think fish could use better ways of breaking long lines.

Contributor

Soares commented Nov 22, 2012

This is great except for when you have significantly long sub commands. Imagine, for example:

(grep "some long piece of text" /some/long/directory | tr -d "FLAG" | cut -c '/' -f 3 | ...)

This can quickly exceed 80 characters. This problem is exacerbated by #159, which rewards keeping text out of fish variables for as long as possible, though it could theoretically happen any time you are trying to run a subcommand with enough arguments.

Another acceptable solution would be to allow line breaking at or before a pipe. Alternatively fish could allow multi-line command substitutions (python sets a good precedent for whitespace in parenthesis). Regardless, I think fish could use better ways of breaking long lines.

@ridiculousfish

This comment has been minimized.

Show comment
Hide comment
@ridiculousfish

ridiculousfish Nov 22, 2012

Member

You are very kind to call the existing behavior "great." I would say it's borderline useless.

The commit referenced in #52 brings fish in line with other shells, where you can use backslash to join two lines into one command (not two commands) in unquoted or double quotes. I think that should resolve this - please reopen if not. Thanks!

Member

ridiculousfish commented Nov 22, 2012

You are very kind to call the existing behavior "great." I would say it's borderline useless.

The commit referenced in #52 brings fish in line with other shells, where you can use backslash to join two lines into one command (not two commands) in unquoted or double quotes. I think that should resolve this - please reopen if not. Thanks!

@maxfl

This comment has been minimized.

Show comment
Hide comment
@maxfl

maxfl Nov 23, 2012

Contributor

This code still doesn't work:

for i in \
    a b c
    echo $i
end
Contributor

maxfl commented Nov 23, 2012

This code still doesn't work:

for i in \
    a b c
    echo $i
end
@siteshwar

This comment has been minimized.

Show comment
Hide comment
@siteshwar

siteshwar Nov 23, 2012

Member

It has been special cased in tokenizer.cpp:539 :

        if ((*(tok->buff) == L'\\') &&(*(tok->buff+1) == L'\n'))
        {
            tok->last_pos = tok->buff - tok->orig_buff;
            tok->buff+=2;
            tok->last_type = TOK_END;
            return;
        }
Member

siteshwar commented Nov 23, 2012

It has been special cased in tokenizer.cpp:539 :

        if ((*(tok->buff) == L'\\') &&(*(tok->buff+1) == L'\n'))
        {
            tok->last_pos = tok->buff - tok->orig_buff;
            tok->buff+=2;
            tok->last_type = TOK_END;
            return;
        }
@maxfl

This comment has been minimized.

Show comment
Hide comment
@maxfl

maxfl Nov 23, 2012

Contributor

It seems that it was done before continuation by '' was introduced.

Contributor

maxfl commented Nov 23, 2012

It seems that it was done before continuation by '' was introduced.

@ridiculousfish

This comment has been minimized.

Show comment
Hide comment
@ridiculousfish

ridiculousfish Nov 23, 2012

Member

Good find siteshwar and maxfl.
Should be fixed here:

To git@github.com:fish-shell/fish-shell.git
654010f..bf27cb1 master -> master

Member

ridiculousfish commented Nov 23, 2012

Good find siteshwar and maxfl.
Should be fixed here:

To git@github.com:fish-shell/fish-shell.git
654010f..bf27cb1 master -> master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment