Skip to content

Instantly share code, notes, and snippets.

@ixti
Last active October 25, 2018 22:15
Show Gist options
  • Save ixti/70096d01b6feb700021576fe6e932dbb to your computer and use it in GitHub Desktop.
Save ixti/70096d01b6feb700021576fe6e932dbb to your computer and use it in GitHub Desktop.
Simple shellcheck wrapper
#!/bin/bash
files=()
args=()
hashbang_regexp="^#\\!(/bin/|/usr/bin/env )?(sh|tcsh|csh|dash|bash)"
function lookup() {
while IFS= read -d $'\0' -r file; do
if [[ "${file}" =~ ^.*\.(ba|c|da|tc|z)?sh$ ]] \
|| head "${file}" -n 1 | grep -E -q "${hashbang_regexp}"; then
files=("${files[@]}" "${file}")
fi
done < <(find "$1" -type f -print0)
}
for arg in "$@"; do
if [[ -d "${arg}" ]]; then
lookup "${arg}"
elif [[ -f "${arg}" ]]; then
files=("${files[@]}" "${arg}")
else
args=("${args[@]}" "${arg}")
fi
shift
done
shellcheck "${args[@]}" "${files[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment