foxundermoon/vs-shell-format

Scripts and startup files (no `.sh` suffix) are not supported.

dseynhae opened this issue · 3 comments

I'm using the formatter in VS Code to manage my Bash startup files.
The Bash IDE language server recognizes that they are written in a supported language.

For my scripts, they require a shebang, and the Bash IDE extension kicks in again...

But the vs-shell-format extension seems to insist on the sh suffix to make the formatter available...

Can we provide an option to explicitly list file names where the formatter should be available? The typical startup file names should just be recognized by default...

Or is there another way to force access to this formatter in VS Code?

I'm using a bit of a hack to resolve the situation: I just create a symbolic link to my prefix-less files:

ln -s <file> <file.sh>

Now I can edit the file with the prefix, but the changes (and formatting) happen to my original file:

core -r <file>.sh
...

It's just a bit messy keeping those links around....

rasa commented

Perhaps it could look at shebang line to see if it's a shell script? The shell script formatting command shfmt has a -f option to recursively scan for shell scripts. This command uses the regex:

^#!\s?/(usr/)?bin/(env\s+)?(sh|bash|mksh|bats|zsh)(\s|$)

on the first line of the file here.

A lot of my scripts are sourced (and hence don't have a shebang line).
The shebang line of course is ignored as a comment when sourcing a file, but I don't like to use a shebang line, because it implies that the script can be executed...

Another problem with the shebang, is that the extension now has to consider every file that gets opened, checking for a shebang line...

So as a first compromise, I would like to see support for files like:

.profile
.bash_profile
.bashrc

Or, any file in particular directories:

.bashrc.d
bin