Skip to content

Instantly share code, notes, and snippets.

@kgaughan
Last active October 12, 2015 18:58
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 kgaughan/4072016 to your computer and use it in GitHub Desktop.
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.
#!/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' {} \;
#!/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