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