indent.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. if [ $# -eq 0 ]; then
  3. echo "usage: $0 <file1 file2 ...>"
  4. exit 1
  5. fi
  6. if [ "$(type -t indent)" = "" ]; then
  7. echo "Please install GNU indent first."
  8. exit 1
  9. fi
  10. # Assume a width of 4 spaces per tab.
  11. # E.g. when indenting to the opening braces of an argument list.
  12. indent \
  13. --line-length160 \
  14. --comment-line-length100 \
  15. --indent-level4 \
  16. --use-tabs \
  17. --tab-size4 \
  18. --case-indentation0 \
  19. --declaration-indentation1 \
  20. --ignore-newlines \
  21. --swallow-optional-blank-lines \
  22. --blank-lines-after-procedures \
  23. --no-blank-lines-after-commas \
  24. --break-after-boolean-operator \
  25. --no-space-after-for \
  26. --no-space-after-if \
  27. --no-space-after-while \
  28. --no-space-after-casts \
  29. --braces-on-if-line \
  30. --braces-on-func-def-line \
  31. --braces-on-struct-decl-line \
  32. --cuddle-do-while \
  33. --cuddle-else \
  34. --dont-break-procedure-type \
  35. --continue-at-parentheses \
  36. --no-space-after-function-call-names \
  37. --no-space-after-parentheses \
  38. --no-comment-delimiters-on-blank-lines \
  39. --comment-indentation0 \
  40. --format-first-column-comments \
  41. --declaration-comment-column0 \
  42. --format-all-comments \
  43. --line-comments-indentation0 \
  44. --blank-lines-before-block-comments \
  45. --space-special-semicolon \
  46. $@
  47. # Remove trailing whitespace
  48. for file in $@; do
  49. sed -i -e's/[[:space:]]*$//' "$file"
  50. done