Last active
August 29, 2015 13:57
-
-
Save kgaughan/9368331 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# | |
# Cleans up basic whitespace problems in .rst and .py files. Run before | |
# commits. | |
# | |
# Tabs to spaces. | |
for i in `fgrep -rl $'\t' --include=\*.py --include=\*.rst .`; do | |
if test -f $i; then | |
tmp=`mktemp` | |
expand --tabs=4 $i >$tmp | |
mv $tmp $i | |
fi | |
done | |
# Spaces to tabs | |
for i in `fgrep -rl $'\t' --include=\*.php --include=\*.html --include=\*.js --include=\*.css --include=\*.mst .`; do | |
if test -f $i; then | |
tmp=`mktemp` | |
unexpand --first-only --tabs=4 $i >$tmp | |
mv $tmp $i | |
fi | |
done | |
# Trailing whitespace | |
for i in `egrep -rl '[[:space:]]$' --include=\*.py --include=\*.php --include=\*.rst --include=\*.js --include=\*.css --include=\*.html --include=\*.mst .`; do | |
if test -f $i; then | |
sed -i 's/\s\+$//g' $i 2>/dev/null | |
fi | |
done | |
# Trailing and leading lines | |
for ext in py rst php js html css mst; do | |
find . -name \*.$ext -type f -exec sed -i -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' {} \; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment