diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index caed0df9..f80494e0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,3 +28,17 @@ repos: # - id: forbid-crlf - id: remove-crlf exclude: ".bat$" + - repo: local + hooks: + - id: dot-sh + name: Check .sh files against bash-it requirements + entry: ./hooks/dot-sh.sh + language: system + files: "\\.sh$" + types: [file] + - id: dot-bash + name: Check .bash files against bash-it requirements + entry: ./hooks/dot-bash.sh + language: system + files: "\\.bash$" + types: [file] diff --git a/aliases/available/vim.aliases.bash b/aliases/available/vim.aliases.bash index 72a37809..d19057d0 100644 --- a/aliases/available/vim.aliases.bash +++ b/aliases/available/vim.aliases.bash @@ -1,3 +1,4 @@ +# shellcheck shell=bash cite 'about-alias' about-alias 'vim abbreviations' diff --git a/clean_files.txt b/clean_files.txt index 2120e418..e02900c6 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -17,6 +17,7 @@ # root directories # docs +hooks # root files # diff --git a/completion/available/cargo.completion.bash b/completion/available/cargo.completion.bash index 46b399e4..d276ee72 100644 --- a/completion/available/cargo.completion.bash +++ b/completion/available/cargo.completion.bash @@ -1,5 +1,4 @@ -#!/usr/bin/env bash - +# shellcheck shell=bash # cargo (Rust package manager) completion if _binary_exists rustup && _binary_exists cargo; then diff --git a/completion/available/knife.completion.bash b/completion/available/knife.completion.bash index cf050e36..83b332f9 100644 --- a/completion/available/knife.completion.bash +++ b/completion/available/knife.completion.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # Published originally as public domain code at https://github.com/wk8/knife-bash-autocomplete diff --git a/completion/available/packer.completion.bash b/completion/available/packer.completion.bash index ea4b7b8c..2301f0f2 100644 --- a/completion/available/packer.completion.bash +++ b/completion/available/packer.completion.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash cite "about-completion" about-completion "packer completion" diff --git a/completion/available/pipx.completion.bash b/completion/available/pipx.completion.bash index 9e34f076..16fd844d 100644 --- a/completion/available/pipx.completion.bash +++ b/completion/available/pipx.completion.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # pipx completion if _command_exists register-python-argcomplete && _command_exists pipx; then diff --git a/completion/available/rustup.completion.bash b/completion/available/rustup.completion.bash index 96822031..1cf8bc95 100644 --- a/completion/available/rustup.completion.bash +++ b/completion/available/rustup.completion.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # rustup (Rust toolchain installer) completion diff --git a/completion/available/sdkman.completion.bash b/completion/available/sdkman.completion.bash index 9888c031..16affe8d 100644 --- a/completion/available/sdkman.completion.bash +++ b/completion/available/sdkman.completion.bash @@ -1,3 +1,4 @@ +# shellcheck shell=bash _sdkman_complete() { local CANDIDATES local CANDIDATE_VERSIONS diff --git a/completion/available/vault.completion.bash b/completion/available/vault.completion.bash index 7d082ee7..9520f166 100644 --- a/completion/available/vault.completion.bash +++ b/completion/available/vault.completion.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash cite "about-completion" about-completion "vault completion" diff --git a/hooks/dot-bash.sh b/hooks/dot-bash.sh new file mode 100755 index 00000000..7a9dc8bc --- /dev/null +++ b/hooks/dot-bash.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +exit_code=0 +for file in "$@"; do + # Confirm file is not executable + # + if [[ -x "${file}" ]]; then + echo "Bash include file \`${file}\` should not be executable" + exit_code=1 + fi + + # Confirm expected schellcheck header + # + LINE1="$(head -n 1 "${file}")" + if [[ "${LINE1}" != "# shellcheck shell=bash" ]]; then + echo "Bash include file \`${file}\` has bad/missing shellcheck header" + exit_code=1 + fi +done + +exit $exit_code diff --git a/hooks/dot-sh.sh b/hooks/dot-sh.sh new file mode 100755 index 00000000..3fa63216 --- /dev/null +++ b/hooks/dot-sh.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +exit_code=0 +for file in "$@"; do + # Confirm file is executable + # + if [[ ! -x "${file}" ]]; then + echo "Bash file \`${file}\` is not executable" + exit_code=1 + fi + + # Confirm expected #! header + # + LINE1="$(head -n 1 "${file}")" + if [[ "${LINE1}" != "#!/usr/bin/env bash" ]]; then + echo "Bash file \`${file}\` has bad/missing #! header" + exit_code=1 + fi +done + +exit $exit_code diff --git a/plugins/available/basher.plugin.bash b/plugins/available/basher.plugin.bash index d226ffcb..2c77cbfa 100644 --- a/plugins/available/basher.plugin.bash +++ b/plugins/available/basher.plugin.bash @@ -1,3 +1,4 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'initializes basher, the shell package manager' diff --git a/themes/90210/90210.theme.bash b/themes/90210/90210.theme.bash index 97c23f0e..180764c8 100644 --- a/themes/90210/90210.theme.bash +++ b/themes/90210/90210.theme.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash SCM_THEME_PROMPT_DIRTY=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" SCM_THEME_PROMPT_PREFIX=" |" diff --git a/themes/agnoster/agnoster.theme.bash b/themes/agnoster/agnoster.theme.bash index 1f3a5acb..ba3e2c9a 100644 --- a/themes/agnoster/agnoster.theme.bash +++ b/themes/agnoster/agnoster.theme.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # vim: ft=bash ts=2 sw=2 sts=2 # # agnoster's Theme - https://gist.github.com/3712874 diff --git a/themes/barbuk/barbuk.theme.bash b/themes/barbuk/barbuk.theme.bash index c7229997..8e09d4be 100644 --- a/themes/barbuk/barbuk.theme.bash +++ b/themes/barbuk/barbuk.theme.bash @@ -1,5 +1,4 @@ -#!/usr/bin/env bash -# shellcheck disable=2034,2154 +# shellcheck shell=bash # Theme custom glyphs SCM_GIT_CHAR_GITLAB=${BARBUK_GITLAB_CHAR:=' '} diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 38c5c895..dd39337e 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -1,3 +1,4 @@ +# shellcheck shell=bash # Define this here so it can be used by all of the Powerline themes THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true} diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 83731614..3239b360 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # shellcheck source=../../themes/powerline/powerline.base.bash . "$BASH_IT/themes/powerline/powerline.base.bash"