Sublime Forum

-plugin idea- "Bashism" detection for shell scripts

#1

Hi all! New here, so I apologize if this belongs in plug-in development, or off-topic, even, but I was looking for a plug-in that at the moment, doesn’t seem to exist! I tend to write a lot of shell scripts to help me automate… everything, ha. And now I want to automate that!

For those unfamiliar with the term, “a ‘bashism’ is a non-POSIX-compliant construct only supported by bash and a handful of other shells, but not by all. Bashisms make your script less portable.”

For those of you familiar with Perl, think Perl::Critic.

There is already a shell command that does this checking called ‘checkbashisms’, what I was hoping to find was something like that for Sublime Plugin, so I can note when I’m using a bashism (or zsh-ism, as that’s my shell of choice) as I write the script, I think it would be nifty! Even if it didn’t include the very handy “tips” checkbashism gives, simple highlighting would be enough for me. In a perfect world, it could create a comment or tooltip popup with info on the bashism, and how to make it posix compliant, like checkbashism.

I know I’m asking a lot, but I ask for a reason. I’d rather not re-invent the wheel, is there anything like this in existence already? (I say this knowing full well checkbashisms works wonders, ha). If not I’ll dig into checkbashisms myself, and try to get a functional plug-in going when I have time, unless anyone else would be up to the task before that. Let me know if there’s any interest beyond me, ha, and if there are any other features I should work in, or ideas on implementing such a thing.

0 Likes

#2

You’re in luck, it already exists!

Have a read through the following and let us know if you need any help:

0 Likes

#3

I KNEW it had to exist, which is exactly why I asked before making my own. Thanks!

EDIT: After looking over ShellCheck, this is EVEN BETTER than a simple check for Bashisms. To quote from the github page, “To point out subtle caveats, corner cases and pitfalls, that may cause an advanced user’s otherwise working script to fail under future circumstances.” YES. Those corner cases, man… I love it.

To use it as a bashisms check, simply include #!/bin/sh rather than bash. It seems to work with all of the more popular shells, so far, giving you shell-specific help, as long as you do so.

PERFECT.

0 Likes