Skip to content

Instantly share code, notes, and snippets.

@jschoolcraft
Created February 4, 2012 01:04
Show Gist options
  • Save jschoolcraft/1734178 to your computer and use it in GitHub Desktop.
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.
#!/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
@jschoolcraft
Copy link
Author

I threw it in scripts/ and then did chmod +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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment