How to clean a codebase, trailing whitespace, new lines etc

I have a code base that is driving me nuts with conflicts due to trailing whitespace. I'd like to clean it up.

I'd want to:

  • Remove all trailing whitespace
  • Remove any newline characters at the end of files
  • Convert all line endings to unix (dos2unix)
  • Convert all leading spaces to tabs, ie 4 spaces to tabs.

  • While ignoring the .git directory.

I'm on OSX Snow Leopard, and in zsh.

so far, i have:

sed -i "" 's/[ \t]*$//' **/*(.)

which works great, but sed adds a new line to the end of every file it touches, which is no good. I dont think sed can be stopped from doing this, so how can i remove these new lines? Theres probably some awk magic to be applied here.

(Complete answers also welcome)

7
задан jhogendorn 16 February 2011 в 01:35
поделиться