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-length100 \
  14. --indent-level4 \
  15. --use-tabs \
  16. --tab-size4 \
  17. --case-indentation0 \
  18. --declaration-indentation1 \
  19. --ignore-newlines \
  20. --swallow-optional-blank-lines \
  21. --blank-lines-after-procedures \
  22. --no-blank-lines-after-commas \
  23. --break-after-boolean-operator \
  24. --no-space-after-for \
  25. --no-space-after-if \
  26. --no-space-after-while \
  27. --no-space-after-casts \
  28. --braces-on-if-line \
  29. --braces-on-func-def-line \
  30. --braces-on-struct-decl-line \
  31. --cuddle-do-while \
  32. --cuddle-else \
  33. --dont-break-procedure-type \
  34. --continue-at-parentheses \
  35. --no-space-after-function-call-names \
  36. --no-space-after-parentheses \
  37. --no-comment-delimiters-on-blank-lines \
  38. --comment-indentation0 \
  39. --format-first-column-comments \
  40. --declaration-comment-column0 \
  41. --format-all-comments \
  42. --line-comments-indentation0 \
  43. --blank-lines-before-block-comments \
  44. --space-special-semicolon \
  45. $@
  46. # Remove trailing whitespace
  47. for file in $@; do
  48. sed -i -e's/[[:space:]]*$//' "$file"
  49. done