Skip to content

Instantly share code, notes, and snippets.

@vmrob
Created March 8, 2014 01:13
Show Gist options
  • Save vmrob/9423533 to your computer and use it in GitHub Desktop.
Save vmrob/9423533 to your computer and use it in GitHub Desktop.
#! /bin/bash
PATH=/C/MinGW/msys/1.0/bin
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
for f in $(find $DIR/common/mekanism -name '*.java'); do
# remove trailing whitespaces
if grep -E $'[\t ]+$' $f > /dev/null ; then
sed -i -r 's/[\t ]+$//g' $f
FORMATTING_FIX=0
fi
# we use these while loops because we only change one
# level on indentation at a time because we only concern
# ourselves with tabs and spaces at the beginning on a
# line
# some lines have spaces between tabs, fix those
while grep -E $'^\t* {1,3}\t' $f > /dev/null ; do
FORMATTING_FIX=0
sed -i -r 's/^(\t*) {1,3}\t/\1\t/g' $f
done
# replace space indentation with tabs
while grep -E $'^\t* ' $f > /dev/null ; do
FORMATTING_FIX=0
sed -i -r 's/^(\t*) /\1\t/g' $f
done
# now we repeat ourselves for good measure and because
# the first problem can be repeated after replacing the
# indentation
while grep -E $'^\t* {1,3}\t' $f > /dev/null ; do
FORMATTING_FIX=0
sed -i -r 's/^(\t*) {1,3}\t/\1\t/g' $f
done
if [ "$FORMATTING_FIX" == "0" ] ; then
echo "fixed formatting in $f"
fi
done
echo "Done! It might be worth manually looking over these files for things I shouldn't fix automatically:"
for f in $(find $DIR/common/mekanism -name '*.java'); do
if grep $'\t [^*]' $f > /dev/null; then
echo $f
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment