le.sh 1.1 KB

1234567891011121314151617181920212223242526272829
  1. # line ending management script
  2. # CRLF - windows default ('\r\n')
  3. # LF - unix default ('\n')
  4. # arguments:
  5. # ?crlf - print all .cpp and .h files with CRLF line endings
  6. # ?lf - print all .cpp and .h files with LF line endings
  7. # crlf - replace line endings in all .cpp and .h files to CRLF
  8. # lf - replace line endings in all .cpp and .h files to LF
  9. if [ "$1" == "?crlf" ] || [ $# -eq 0 ]; then
  10. echo 'cpp and h files with CRLF line endings:'
  11. find {*.cpp,*.h} -not -type d -exec file "{}" ";" | grep CRLF | sed 's/:.*//g'
  12. elif [ "$1" == "?lf" ]; then
  13. echo 'cpp and h files with LF line endings:'
  14. find {*.cpp,*.h} -not -type d -exec file "{}" ";" | grep -v CRLF | sed 's/:.*//g'
  15. fi
  16. if [ "$1" == "crlf" ]; then
  17. echo 'replacing LF with CRLF in all cpp and h files:'
  18. find {*.cpp,*.h} -not -type d -exec file "{}" ";" | grep -v CRLF | sed 's/:.*//g' | while read fn; do
  19. echo "$fn"
  20. sed -i 's/$/\r/g' $fn
  21. done
  22. elif [ "$1" == "lf" ]; then
  23. echo 'replacing CRLF with LF in all cpp and h files:'
  24. find {*.cpp,*.h} -not -type d -exec file "{}" ";" | grep CRLF | sed 's/:.*//g' | while read fn; do
  25. echo "$fn"
  26. sed -i 's/\r\n/\n/g' $fn
  27. done
  28. fi