focusaurus/atom-format-shell

shfmt supports files without extensions but format-shell does not

Closed this issue · 8 comments

a2daj commented

The shfmt tool this plugin uses supports scripts without file extensions but this plugin explicitly requires files that end in .sh. Is there any particular reason why it is implemented this way?

Mostly to prevent accidentally activating it on an non-shell file, and that the plugin I used as a template for this one did something similar. I'd be willing to remove that check if you think that would be useful. Do you?

a2daj commented

Personally, I think it would nice, so I don't have to touch the command line for my scripts without it. We have a certain naming policy for our shell scripts based on what they do and so we have some with and without .sh.

a2daj commented

shfmt also supports folders and handles things recursively. Would that be tricky to implement with the Atom plugin? I can open up a new issue if it sounds feasible.

Recursive formatting is not something I've seen in an editor plugin such as this. I think the command line is the better tool for that use case.

a2daj commented

That's a good point.

OK v2.0.0 published. Still requires the buffer have the shell grammar applied but no requirements regarding filename.

mvdan commented

FWIW, the folder recursion logic has some code to decide whether or not a file is shell: https://godoc.org/github.com/mvdan/sh/fileutil

I don't know if this could be useful here. In any case, I assume Atom already has something similar to trigger the shell grammar on the buffer.

Yeah atom will auto-detect the appropriate grammar based on filename and shebang line, or you can manually set it as well (which I do if I'm just composing a temporary snippet sometimes).