Created
February 4, 2012 01:04
-
-
Save jschoolcraft/1734178 to your computer and use it in GitHub Desktop.
Used to clean up rubyish code, make unix line endings, tabs to spaces, kill trailing whitespace.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
main() { | |
find_files | | |
exclude_vcs_dirs | | |
exclude_common_dirs_that_are_not_ours | | |
exclude_extra_dirs | | |
cleanup_the_code | |
} | |
find_files() { | |
find -E . -iregex '.*(rb|html|erb|rhtml|rjs|plain|rxml|yml|rake|eml|css|scss|sass|haml|js)$' | |
} | |
exclude_vcs_dirs() { | |
grep -v -e '.git/' -e '.svn/' | |
} | |
exclude_lock_files() { | |
grep -v '.lock' | |
} | |
exclude_common_dirs_that_are_not_ours() { | |
grep -v -e 'vendor/' -e 'tmp/' -e 'public/' -e 'images/' -e 'img/' | |
} | |
exclude_extra_dirs() { | |
grep -v -e 'vendor_archive/' | |
} | |
cleanup_the_code() { | |
xargs -I{} sed -i '' -E -e "s/[[:space:]]*$//" -e "s/`printf '\t'`/ /g" -e "s/\r\n$/\n/" {} | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I threw it in
scripts/
and then didchmod +x scripts/code_cleanup.sh
and finally./scripts/code_cleanup.sh
It is destructive, there are no backups (hopefully you're using git), but it should work as advertised.
Inspired by lots of code and stackoverflow and helped along with man pages, including: