check-nl-at-eof.sh 511 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. cd -P -- "$(dirname -- "$0")/.."
  4. nl_at_eof() {
  5. local file="$1"
  6. if ! [ -f "$file" ]; then
  7. return
  8. fi
  9. case "$file" in
  10. *.png|*rebar3)
  11. return
  12. ;;
  13. esac
  14. local lastbyte
  15. lastbyte="$(tail -c 1 "$file" 2>&1)"
  16. if [ "$lastbyte" != '' ]; then
  17. echo "$file"
  18. return 1
  19. fi
  20. }
  21. n=0
  22. while read -r file; do
  23. if ! nl_at_eof "$file"; then
  24. n=$(( n + 1 ))
  25. fi
  26. done < <(git ls-files)
  27. exit $n