koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
36.39k stars 1.78k forks source link

Support for Shell Script Loader #1975

Open bobvanderlinden opened 4 years ago

bobvanderlinden commented 4 years ago

Shell Script Loader is a framework for Bash/ZSH/etc to include other helper scripts without them being sourced twice and them being sourced from some predefined search-path.

See https://loader.sourceforge.io/

I wanted to use this in my shell script, but shellcheck doesn't have support for such functions as include.

Example:

A file named a.sh:

some_variable=a

A file named b.sh:

include a.sh

echo $some_variable

Supporting such a framework avoids having to do things like:

# shellcheck source=a.sh
[ -n "$A_SH_SOURCED" ] || source "$(dirname "${BASH_SOURCE[0]}")/a.sh"
charlescanato commented 4 years ago

@bobvanderlinden , seems like an interesting library, I'll also take a look.

But I got curious: what support would shellcheck have to provide? I can understand it could be a tiny pain to add shellcheck source directives, but it doesn't seem that dirty to me.

rayzr522 commented 4 years ago

in the given example it's very little overhead, but I imagine with a potentially complex web of include's it could get very painful to manually add source directives for all of them with shellcheck

I know I personally have such a complex dotfile setup :p