Last active
August 29, 2015 14:02
-
-
Save tjmcewan/ed0f3b4e810b54ddec41 to your computer and use it in GitHub Desktop.
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
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