Add hooks to check .sh and .bash headers - Fixes #1491 (#1765)

* Add hooks to check .sh and .bash headers
* Adds hooks/ to clean_files.txt
pull/1778/head
David Farrell 2021-01-09 08:02:26 -08:00 committed by GitHub
parent 3fce1ffe8d
commit e932d8371f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 71 additions and 12 deletions

View File

@ -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]

View File

@ -1,3 +1,4 @@
# shellcheck shell=bash
cite 'about-alias'
about-alias 'vim abbreviations'

View File

@ -17,6 +17,7 @@
# root directories
#
docs
hooks
# root files
#

View File

@ -1,5 +1,4 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# cargo (Rust package manager) completion
if _binary_exists rustup && _binary_exists cargo; then

View File

@ -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

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
# shellcheck shell=bash
cite "about-completion"
about-completion "packer completion"

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# pipx completion
if _command_exists register-python-argcomplete && _command_exists pipx; then

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# rustup (Rust toolchain installer) completion

View File

@ -1,3 +1,4 @@
# shellcheck shell=bash
_sdkman_complete() {
local CANDIDATES
local CANDIDATE_VERSIONS

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
# shellcheck shell=bash
cite "about-completion"
about-completion "vault completion"

21
hooks/dot-bash.sh 100755
View File

@ -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

21
hooks/dot-sh.sh 100755
View File

@ -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

View File

@ -1,3 +1,4 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'initializes basher, the shell package manager'

View File

@ -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=" |"

View File

@ -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

View File

@ -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:=' '}

View File

@ -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}

View File

@ -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"