Add hooks to check .sh and .bash headers

pull/1765/head
David Farrell 2021-01-05 12:37:48 -08:00
parent 3c00fe6dbb
commit 15edc2cd52
No known key found for this signature in database
GPG Key ID: 1CCA28D0E300B56F
14 changed files with 90 additions and 9 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,5 @@
#!/usr/bin/env echo run from bash: .
# shellcheck shell=bash disable=SC2148,SC2096
cite 'about-alias'
about-alias 'vim abbreviations'

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#!/usr/bin/env echo run from bash: .
# shellcheck shell=bash disable=SC2148,SC2096
# cargo (Rust package manager) completion
if _binary_exists rustup && _binary_exists cargo; then

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash
#!/usr/bin/env echo run from bash: .
# shellcheck shell=bash disable=SC2148,SC2096
# Published originally as public domain code at https://github.com/wk8/knife-bash-autocomplete

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash
#!/usr/bin/env echo run from bash: .
# shellcheck shell=bash disable=SC2148,SC2096
cite "about-completion"
about-completion "packer completion"

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash
#!/usr/bin/env echo run from bash: .
# shellcheck shell=bash disable=SC2148,SC2096
# pipx completion
if _command_exists register-python-argcomplete && _command_exists pipx; then

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash
#!/usr/bin/env echo run from bash: .
# shellcheck shell=bash disable=SC2148,SC2096
# rustup (Rust toolchain installer) completion

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash
#!/usr/bin/env echo run from bash: .
# shellcheck shell=bash disable=SC2148,SC2096
cite "about-completion"
about-completion "vault completion"

31
hooks/dot-bash.sh 100755
View File

@ -0,0 +1,31 @@
#!/usr/bin/env bash
exit_code=0
for file in "$@"; do
# TODO Confirm file has '.bash' extension
# Confirm not executable
#
if [[ -x "${file}" ]]; then
echo "Bash include file \`${file}\` should not be executable"
exit_code=1
fi
# Confirm expected #! header
#
LINE1="$(head -n 1 "${file}")"
if [[ "${LINE1}" != "#!/usr/bin/env echo run from bash: ." ]]; then
echo "Bash include file \`${file}\` has bad/missing #! header"
exit_code=1
fi
# Confirm expected schellcheck header
#
LINE2="$(head -n 2 "${file}" | tail -n 1)"
if [[ "${LINE2}" != "# shellcheck shell=bash disable=SC2148,SC2096" ]]; then
echo "Bash include file \`${file}\` has bad/missing shellcheck header"
exit_code=1
fi
done
exit $exit_code

23
hooks/dot-sh.sh 100755
View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
exit_code=0
for file in "$@"; do
# TODO Confirm file has '.sh' extension
# 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,5 @@
#!/usr/bin/env echo run from bash: .
# shellcheck shell=bash disable=SC2148,SC2096
cite about-plugin
about-plugin 'initializes basher, the shell package manager'

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash
#!/usr/bin/env echo run from bash: .
# shellcheck shell=bash disable=SC2148,SC2096
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX=" |"

View File

@ -1,3 +1,5 @@
#!/usr/bin/env echo run from bash: .
# shellcheck shell=bash disable=SC2148,SC2096
# 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,5 @@
#!/usr/bin/env bash
#!/usr/bin/env echo run from bash: .
# shellcheck shell=bash disable=SC2148,SC2096
# shellcheck source=../../themes/powerline/powerline.base.bash
. "$BASH_IT/themes/powerline/powerline.base.bash"