reformat-all.sh 695 B

12345678910111213141516171819202122
  1. #!/bin/bash
  2. _CLANG_FORMAT=${CLANG_FORMAT-"clang-format"}
  3. if ! command -v "$_CLANG_FORMAT" &>/dev/null ; then
  4. echo "You must install clang-format and add it to your PATH." >&2
  5. echo " See: http://releases.llvm.org/download.html" >&2
  6. echo "Use CLANG_FORMAT=/path/to/clang-format if you do not want it in PATH. " >&2
  7. exit 1
  8. fi
  9. cd "$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
  10. cd ..
  11. DIFF_BEFORE=$(git diff | wc -l)
  12. echo "Difference before format: $DIFF_BEFORE"
  13. find lib -iname *.h -o -iname *.c -o -iname *.cpp -o -iname *.hpp | xargs "$_CLANG_FORMAT" -i
  14. DIFF_AFTER=$(git diff | wc -l)
  15. echo "Difference after format: $DIFF_AFTER (delta: $(($DIFF_BEFORE - $DIFF_AFTER)))"