indent.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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-length120 \
  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. --space-special-semicolon \
  45. $@
  46. # Remove trailing whitespace
  47. for file in $@; do
  48. sed -i -e's/[[:space:]]*$//' "$file"
  49. done