build.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env bash
  2. set -eo pipefail
  3. [[ "${DEBUG:-}" ]] && set -x
  4. success() {
  5. printf "\r\033[2K [ \033[00;32mOK\033[0m ] Linting %s...\n" "$1"
  6. }
  7. fail() {
  8. printf "\r\033[2K [\033[0;31mFAIL\033[0m] Linting %s...\n" "$1"
  9. exit 1
  10. }
  11. check() {
  12. local script="$1"
  13. shellcheck "$script" || fail "$script"
  14. success "$script"
  15. }
  16. find_prunes() {
  17. local prunes="! -path './.git/*'"
  18. if [ -f .gitmodules ]; then
  19. while read module; do
  20. prunes="$prunes ! -path './$module/*'"
  21. done < <(grep path .gitmodules | awk '{print $3}')
  22. fi
  23. echo "$prunes"
  24. }
  25. find_cmd() {
  26. echo "find . -type f -and \( -perm +111 -or -name '*.sh' \) $(find_prunes)"
  27. }
  28. check_all_executables() {
  29. echo "Linting all executables and .sh files, ignoring files inside git modules..."
  30. eval "$(find_cmd)" | while read script; do
  31. head=$(head -n1 "$script")
  32. [[ "$head" =~ .*ruby.* ]] && continue
  33. [[ "$head" =~ .*zsh.* ]] && continue
  34. [[ "$head" =~ ^#compdef.* ]] && continue
  35. check "$script"
  36. done
  37. }
  38. check_all_executables