focusaurus / atom-format-shell

Format shell script from within atom text editor
MIT License
6 stars 1 forks source link

shfmt supports files without extensions but format-shell does not #3

Closed a2daj closed 7 years ago

a2daj commented 7 years ago

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?

focusaurus commented 7 years ago

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 7 years ago

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 7 years ago

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.

focusaurus commented 7 years ago

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 7 years ago

That's a good point.

focusaurus commented 7 years ago

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

mvdan commented 7 years ago

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.

focusaurus commented 7 years ago

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).