Replies: 2 comments
-
Truly unbelievable that nothing like feat 1 appears to exist after checks notes 52 years of the Unix shell existing with syntax amenable to such a re-formatting. (Hopefully, by Cunningham's Law, someone will come to prove me wrong). |
Beta Was this translation helpful? Give feedback.
0 replies
-
https://github.com/noperator/sol accomplishes feat 1. For example, using # one-liner
$ cat command.sh
echo -n 'this string with a few words' | wc -l | sed -E 's/^ +//'~/g/n/sol main
# break on binary commands (e.g., pipe) when we reach 30 characters wide
$ cat command.sh | sol -b -w 30
echo -n 'this string with a few words' |
wc -l | sed -E 's/^ +//' Uses |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I have a couple of feature requests that I'd like to discuss/suggest for
shfmt
.Feat 1:
break long lines
See #80
This is one that I'd really like to see implemented. I think it'd be nice if
shfmt
broke/hard-wrapped long lines at a configurable number of characters, or if it at least provided the option to do so. Otherwise, long lines need to be broken by hand (or via some, additional, custom solution that is hopefully syntax-aware). Most formatters (e.g.prettier
,rustfmt
,stylua
, etc.) do this by default, and usually let you configure a target line length as well. It seems thatshfmt
does not do this by default, and I couldn't find an option to specify line length. It could apply to the entire file (generally speaking), but it's something that is mainly needed for lengthycmd1 && cmd2
andcmd1 | cmd2
type of lines (i.e. pipelines and cmd lists, or whatever they are technically called). It seems thatshfmt
will break on semi-colons (e.g.cmd1; cmd2
), but not on&&
,||
, nor|
, etc. It would also be nice to have the option to break on command arguments as well.For example, if a line is longer than n chars (where
n
is configurable), break it according to some strategy (which is perhaps configurable as well). Maybe the default strategy could simply be to put every additional word on a separate line, indented relative to the 1st word of that line:### don't break short lines foo && bar && baz foo bar baz foo --bar baz foo --bar --baz
while, of course, breaking the lines according to the value of
-bn
, indenting according to-i
, etc..And, do the same for cmd args/opts, although I'm unsure what the potential caveats of this are tbh (perhaps it may ruin things in environments where
IFS
is set to an abnormal value that doesn't contain newline?). Maybe this should be enabled via its own, separate option (separate from the kind of line-breaking on||
,&&
, and|
shown above)?However, breaking on both at the same time is when things start to get tricky, as the possibilities for how to do so (in regards to indentation) multiply.
Feat 2:
option to print resolved config and/or config paths
For example,
prettier
accepts the following option to print which config files will be used:and some tools allow you to view its resolved configuration (i.e. not just the paths to the files, but the ultimate/final option values themselves) for a given invocation. This is another thing that'd be nice to have (mainly for debugging/testing, interrogation/introspection, understanding how the tool works, etc.), but isn't super important, although I imagine it'd be fairly easy to implement.
Beta Was this translation helpful? Give feedback.
All reactions