Skip to content
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

request: allow ; shift to remain at the end of lines #679

Open
andreykaipov opened this issue Feb 26, 2021 · 3 comments
Open

request: allow ; shift to remain at the end of lines #679

andreykaipov opened this issue Feb 26, 2021 · 3 comments

Comments

@andreykaipov
Copy link
Contributor

andreykaipov commented Feb 26, 2021

I figured since there's already some options for indenting switch cases or putting a space after redirect operators, you also might be open to supporting the following pattern:

f() {
  a="$1"; shift
  b="$1"; shift
  c="$1"; shift
  echo "$a $b $c"
}

Here's a few examples from shell scripts of popular projects where this pattern could be found:

https://github.com/ohmybash/oh-my-bash/blob/master/themes/colours.theme.sh
https://github.com/sonph/onehalf/blob/master/gnome-terminal/onehalfdark.sh#L84-L106
https://github.com/kohler/click/blob/master/click-compile.in#L43-L85

I'm going to look through the code to see if it's something I could tackle, but in the meantime figured I'd open this request. If you don't think it's something you'd like to support, that's okay. I still really appreciate the tool!

Thanks!

@andreykaipov andreykaipov changed the title request: allow `"$1; shift on one line request: allow "$1"; shift Feb 26, 2021
@andreykaipov andreykaipov changed the title request: allow "$1"; shift request: allow ; shift to remain at the end of lines Feb 26, 2021
@mvdan
Copy link
Owner

mvdan commented Mar 4, 2021

You might be interested in #564. It's a similar kind of feature, but for a good reason; since Bash parses lines one by one, spliting foo; exit $? into multiple lines could result in corrupted code being run.

Other people have asked for ways to have "one-liners", such as #591 #602 #261. The problem is - where do we draw the line? I certainly don't want to allow multiple commands on a single line in general, as that would make the formatting too inconsistent.

So my default stance is to only allow the exit case, where it actually affects the behavior of a script. All other cases seem to be about personal preference, and at the end of the day the formatting tool is always a compromise between consistency and everyone's personal preferences.

I will say that I find this case more commonly useful than the other cases which have been brought up, since this is a useful (and the only) way to have named parameters in a function declaration. Maybe it would be reasonable to pattern-match local NAME=VALUE; shift and allow that to be on a single line.

@devkapilbansal
Copy link

I too want to avoid this formatting
Shift in multiline

@mvdan are you planning to work on this ?

I think the never-split function introduce here is something similar, although I haven't checked it as that repository is a lot behind this and may have bugs/less features too.

@mvdan
Copy link
Owner

mvdan commented Aug 11, 2021

Please don't paste large screenshots of text. Just paste the text.

We'll definitely not add a feature like never-split. You're free to use forks, but those are different projects entirely.

My thinking is still leaning in favor of doing this, see my last comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants