-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
syntax: allow printing redirections before all arguments #942
Comments
The formatter wants to enforce a somewhat canonical and consistent format - it could be far more conservative and only fix up whitespace like indentation, but then it would be far less useful in practice :) I realise that redirections can appear anywhere, but we currently only allow them after the first argument, or after all arguments. See #389 for a previous discussion. I guess we could also allow them to appear before all arguments as a third option. That isn't a big change, and you're not the first person to suggest it (cc @dcsobral @ale5000-git), so perhaps I should reconsider. One objective reason in favor of supporting it is that, in your example, keeping the redirections in the first place does help with alignment. In some other cases, the alignment could be better if the redirection was after the first argument - the user can choose in each instance. I don't think we should get into the business of writing a heuristic for it. |
@mvdan Thank you for the reference to #389 and pointing out that
👍 Out of curiosity, do you have an example of these some other cases?
is more easy to skim than this
Most importantly, thank you for your continued work on |
If your redirections are all the same length, but the commands aren't, then placing them first helps with alignment:
In the opposite scenario, it helps to place the first argument at the beginning:
|
@mvdan Thank you. |
Sometimes, to improve readability, I put logfile redirections at the beginning of the line:
This is currently, as of shfmt v3.5.1, incorrectly reformatted as follows:
Research
Putting redirects at various places in-between arguments and at the end seems to have been supported from the very beginning of
sh
in 1971. Putting redirects at the beginning was not supported in UNIX V1, but emerged sometime later. I haven't found out when.UNIX V1 manual (1971-03-11) (and code):
Bash documentation, section 3.6 (2022-11-13):
Bash documentation, section 3.7.1 (2022-11-13):
The text was updated successfully, but these errors were encountered: