Script: Strip trailing whitespaces and force new line at end of file
Many editors/ IDEs now support this code style rules. If you don't want to have to open every single file of a project and save each of them, you can use this script. It is somewhat adapted to the case of Drupal, but can be used in other cases too with some tweaks.
<?php
#!/bin/bash
# strip trailing white spaces.
for ext in "info" "css" "txt" "sh" "profile" "install" "test" "module" "inc" "php" "js"
do
find . -type f -name "*.$ext" -exec sed -i 's/[[:space:]]*$//' {} ;
done
# ensures all files end with a newline.
for ext in "info" "css" "txt" "sh" "profile" "install" "test" "module" "inc" "php" "js"
do
find . -type f -name "*.$ext" -print | xargs printf "e %s\nw\n" | ed -s;
done
?>
Comments
Add new comment