|
|
@ -7,14 +7,32 @@ if hash black 2>/dev/null; then
|
|
|
|
|
|
|
|
|
|
|
|
# Find all of the .py files in the current git repo, apply black formatting to them and then
|
|
|
|
# Find all of the .py files in the current git repo, apply black formatting to them and then
|
|
|
|
# add them again
|
|
|
|
# add them again
|
|
|
|
git diff --cached --name-status | \
|
|
|
|
cached_files=$(git diff --cached --name-status | \
|
|
|
|
grep -v '^D' | grep '\.py' | \
|
|
|
|
grep -v '^D' | grep '\.py' | \
|
|
|
|
sed 's/[A-Z][ \t]*//' | \
|
|
|
|
sed 's/[A-Z][ \t]*//')
|
|
|
|
xargs black 2>&1| \
|
|
|
|
|
|
|
|
grep '^reformatted' | \
|
|
|
|
|
|
|
|
sed 's/reformatted[ \t]//' | \
|
|
|
|
|
|
|
|
xargs git add
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Only run if we have cached python files
|
|
|
|
|
|
|
|
if [ "$cached_files" ]; then
|
|
|
|
|
|
|
|
black --line-length 100 $cached_files
|
|
|
|
|
|
|
|
git add $cached_files
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
echo "Black isn't installed so not formatting python code"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Only run if intellij is set up
|
|
|
|
|
|
|
|
if hash idea.sh 2>/dev/null; then
|
|
|
|
|
|
|
|
# Apply intellij
|
|
|
|
|
|
|
|
cached_files=$(git diff --cached --name-status | \
|
|
|
|
|
|
|
|
grep -v '^D' | grep '\.java' | \
|
|
|
|
|
|
|
|
sed 's/[A-Z][ \t]*//')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$cached_files" ]; then
|
|
|
|
|
|
|
|
idea.sh format -allowDefaults $cached_files 2>/dev/null
|
|
|
|
|
|
|
|
git add $cached_files
|
|
|
|
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
else
|
|
|
|
"Black isn't installed so not formatting python code"
|
|
|
|
echo "intellij isn't installed so not formatting java code"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|