#!/usr/bin/env bash

# Run static analysis on bash scripts.

# Exit on first failing command.
set -e

# Exit on unset variable.
set -u

BASH_SCRIPTS=()

while read -r filepath; do
  # Check shebang for bash.
  if head -n 1 "${filepath}" | grep --quiet --regexp 'bash'; then
      BASH_SCRIPTS+=("${filepath}")
  fi
done < <(git ls-files)

readonly BASH_SCRIPTS

# Echo commands before executing them, by default to stderr.
set -x

shellcheck "${BASH_SCRIPTS[@]}"
