add bash-it
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
file=$1
|
||||
# Should only be run on clean_files.txt
|
||||
if [ "$file" != "clean_files.txt" ]; then
|
||||
echo "Please run this script on clean_files.txt only!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
function compare_lines() {
|
||||
prev=""
|
||||
while read -r line; do
|
||||
# Skip unimportant lines
|
||||
[[ $line =~ "#" ]] && continue
|
||||
[[ $line == "" ]] && continue
|
||||
# Actual check
|
||||
if [[ $prev > $line ]]; then
|
||||
echo "$line should be before $prev"
|
||||
exit 1
|
||||
fi
|
||||
prev=$line
|
||||
done <<< "$1"
|
||||
}
|
||||
|
||||
# We compare using the legacy way
|
||||
shopt -s compat31
|
||||
|
||||
# Test root files
|
||||
compare_lines "$(grep -v "/" "$file")"
|
||||
|
||||
# Test root directory
|
||||
compare_lines "$(grep "/$" "$file")"
|
||||
|
||||
# Test non root directories
|
||||
compare_lines "$(grep "/." "$file")"
|
||||
|
||||
shopt -u compat31
|
||||
# Yay, all good!
|
||||
exit 0
|
||||
@@ -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:-0}"
|
||||
@@ -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:-0}"
|
||||
Reference in New Issue
Block a user