spicypete 10 days ago

I use `mvdan/sh` [1] under the hood for processing the commands. So it will reformat

  if [ foo ] ; then
    bar
  fi
to

  if [ foo ]
  then
    bar
  fi
And also format your example to

  foo
  bar
In this type of situation, it becomes a little trickier to disambiguate when I need to add semicolons and a backslash, and when I need to add only backslashes. If you use `&&` -- you have disambiguated the two cases so I can format it.

[1] https://github.com/mvdan/sh

1
yjftsjthsd-h 10 days ago

Between that and the difficulty with comments, it feels like maybe not an ideal tool for the job? Although, I can't throw stones; I'd do almost anything to avoid having to write my own parser. (And not meant as an attack regardless, just trying to constructively question this particular design point)

spicypete 10 days ago

I am certainly not in the business of writing my own shell parser ;) Though this is a fair point -- I think I could get a more rich level of control over the output by hooking into their parser, albeit with a higher level of complexity.

yjftsjthsd-h 10 days ago

/shrug Something to think about. Usually I'd say not to worry about it, but this particular point seems to be actively causing actual problems, so it might be worth looking at. Alternatively, if the pain points you've discovered really are all there are to find, then it might well be less trouble to just patch over them specifically and not worry about it. Ugly solutions that work well and don't take extra work are good solutions in my book;)