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

Feature idea: wrap command arguments to multiple lines #690

Closed
mikez opened this issue Mar 28, 2021 · 4 comments
Closed

Feature idea: wrap command arguments to multiple lines #690

mikez opened this issue Mar 28, 2021 · 4 comments

Comments

@mikez
Copy link

mikez commented Mar 28, 2021

Python

In Python code formatters, long lines like these:

create_join_index(self.right.index, self.left.index, right_indexer, left_indexer, how="left")

get changed to

create_join_index(
    self.right.index,
    self.left.index,
    right_indexer,
    left_indexer,
    how="left",
)

Bash

How about, in bash, if sufficiently long lines:

ffmpeg -ss 12:34 -i https://example.com/video.mp4 -vframes 1 -q:v 2 path/to/wonderful/screenshot.jpg

were changed to

ffmpeg \
    -ss 12:34 \
    -i https://example.com/video.mp4 \
    -vframes 1 \
    -q:v 2 \
    path/to/wonderful/screenshot.jpg

There would be some heuristics involved, but even a close approximation would save lots of reformatting. Are there any libraries or scripts around attempting to do this already?

@mikez mikez changed the title Feature idea: wrap commandline arguments to multiple lines Feature idea: wrap command arguments to multiple lines Mar 28, 2021
@mvdan
Copy link
Owner

mvdan commented Mar 30, 2021

In general, I'd say the answer in shfmt for this is #80.

If you want stricter rules, like "one argument/flag per line", I think that's too strict/aggressive for a tool as generic as shfmt. But you could certainly write a tool very similar to shfmt which applies extra transformations; the syntax package contains both parsing and printing of programs.

@mikez
Copy link
Author

mikez commented Mar 30, 2021

👍

It wouldn't have to be the default, but maybe something one can enable via configuration settings. Most other languages I work in have code formatters that let you wrap lines automatically in some form or the other.

Thank you for writing this tool, it's been very helpful. ☀️

@mikez mikez closed this as completed Mar 30, 2021
@noperator
Copy link

@mikez, https://github.com/noperator/sol will do this for you. For example, using sol -a:

$ echo 'ffmpeg -ss 12:34 -i https://example.com/video.mp4 -vframes 1 -q:v 2 path/to/wonderful/screenshot.jpg' | sol -a

ffmpeg \
    -ss 12:34 \
    -i https://example.com/video.mp4 \
    -vframes 1 \
    -q:v 2 path/to/wonderful/screenshot.jpg

There would be some heuristics involved, but even a close approximation would save lots of reformatting.

Agree—I use sol to handle 95% of formatting and then tweak the result as needed. In this case, you may want to manually insert a line break before the final path argument.

@mikez
Copy link
Author

mikez commented Sep 3, 2024

@noperator Thanks for the pointer to your package! 😵‍💫😎

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