lint-shell-scripts.sh 858 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bash
  2. set -eo pipefail
  3. script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
  4. cd "$script_path/.."
  5. if [ "$#" -eq "0" ]; then
  6. mapfile -t files < <(
  7. git ls-files -- \
  8. '*.sh' \
  9. ':!:Ports' \
  10. ':!:Userland/Shell/Tests' \
  11. ':!:Base/home/anon/tests' \
  12. ':!:Base/root/generate_manpages.sh'
  13. )
  14. else
  15. files=()
  16. for file in "$@"; do
  17. if [[ "${file}" == *".sh" && "${file}" != "Base/root/generate_manpages.sh" ]]; then
  18. files+=("${file}")
  19. fi
  20. done
  21. fi
  22. if (( ${#files[@]} )); then
  23. if ! command -v shellcheck &>/dev/null ; then
  24. echo "shellcheck is not available, but shell files need linting! Either skip this script, or install shellcheck."
  25. exit 1
  26. fi
  27. shellcheck "${files[@]}"
  28. else
  29. echo "No .sh files to check."
  30. fi