Skip to content

Instantly share code, notes, and snippets.

@tjmcewan
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjmcewan/ed0f3b4e810b54ddec41 to your computer and use it in GitHub Desktop.
Save tjmcewan/ed0f3b4e810b54ddec41 to your computer and use it in GitHub Desktop.
exclude_patterns() {
exclude="-false" # need to start the list somewhere so we have the right number of "-or"
for exclude_folder in .git .bundle tmp log; do
exclude="$exclude -or -name $exclude_folder -prune"
done
for exclude_file in Gemfile.lock structure.sql '*.gif' '*.jpg' '*.png' '*jquery*' '*.doc' '*.pdf' '*.zip' '*.ico' '*.swf' '*.sqlite' '*.ttf'; do
exclude="$exclude -or -iname $exclude_file"
done
echo $exclude
}
code_file_list() {
find "${@:-.}" -not \( $(exclude_patterns) \) -type f -print0
}
normalise_files() {
while IFS= read -d $'\0' -r file; do
# `` strips all EOF newlines, printf straight echoes the file
# line endings: tr
# \r\n => \n for Win
# \r => \n for Mac
# whitespace & newline at EOF: sed
# tabs -> 2 spaces: expand
echo $file
printf '%s' "`cat $file`" | tr '\r\n' '\n' | tr '\r' '\n' | sed -E 's/[[:blank:]]+$//' | expand -t 2 > "$file.tmp"
mv "$file.tmp" "$file"
done < <(code_file_list $@)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment