* Add hooks to check .sh and .bash headers * Adds hooks/ to clean_files.txt
This commit is contained in:
21
hooks/dot-bash.sh
Executable file
21
hooks/dot-bash.sh
Executable 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
Executable file
21
hooks/dot-sh.sh
Executable 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
|
||||
Reference in New Issue
Block a user