Skip to content

Commit

Permalink
Add hooks to check .sh and .bash headers - Fixes #1491 (#1765)
Browse files Browse the repository at this point in the history
* Add hooks to check .sh and .bash headers
* Adds hooks/ to clean_files.txt
  • Loading branch information
davidpfarrell committed Jan 9, 2021
1 parent 3fce1ff commit e932d83
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 12 deletions.
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
1 change: 1 addition & 0 deletions aliases/available/vim.aliases.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shellcheck shell=bash
cite 'about-alias'
about-alias 'vim abbreviations'

Expand Down
1 change: 1 addition & 0 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# root directories
#
docs
hooks

# root files
#
Expand Down
3 changes: 1 addition & 2 deletions completion/available/cargo.completion.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash

# shellcheck shell=bash
# cargo (Rust package manager) completion

if _binary_exists rustup && _binary_exists cargo; then
Expand Down
2 changes: 1 addition & 1 deletion completion/available/knife.completion.bash
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion completion/available/packer.completion.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
# shellcheck shell=bash
cite "about-completion"
about-completion "packer completion"

Expand Down
2 changes: 1 addition & 1 deletion completion/available/pipx.completion.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
# shellcheck shell=bash
# pipx completion

if _command_exists register-python-argcomplete && _command_exists pipx; then
Expand Down
2 changes: 1 addition & 1 deletion completion/available/rustup.completion.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
# shellcheck shell=bash

# rustup (Rust toolchain installer) completion

Expand Down
1 change: 1 addition & 0 deletions completion/available/sdkman.completion.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shellcheck shell=bash
_sdkman_complete() {
local CANDIDATES
local CANDIDATE_VERSIONS
Expand Down
2 changes: 1 addition & 1 deletion completion/available/vault.completion.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
# shellcheck shell=bash
cite "about-completion"
about-completion "vault completion"

Expand Down
21 changes: 21 additions & 0 deletions hooks/dot-bash.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 21 additions & 0 deletions hooks/dot-sh.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions plugins/available/basher.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'initializes basher, the shell package manager'

Expand Down
2 changes: 1 addition & 1 deletion themes/90210/90210.theme.bash
Original file line number Diff line number Diff line change
@@ -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=" |"
Expand Down
2 changes: 1 addition & 1 deletion themes/agnoster/agnoster.theme.bash
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions themes/barbuk/barbuk.theme.bash
Original file line number Diff line number Diff line change
@@ -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:=''}
Expand Down
1 change: 1 addition & 0 deletions themes/powerline/powerline.base.bash
Original file line number Diff line number Diff line change
@@ -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}

Expand Down
2 changes: 1 addition & 1 deletion themes/powerline/powerline.theme.bash
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit e932d83

Please sign in to comment.