You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
648 B
21 lines
648 B
11 months ago
|
#!/bin/bash
|
||
|
# This is a script which can be included in a pre-commit hook to auto format code using specified
|
||
|
# tools. In this script we utilize black for python and intelliJ for Java.
|
||
|
|
||
|
# Only run if black is installed
|
||
|
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
|
||
|
# add them again
|
||
|
git diff --cached --name-status | \
|
||
|
grep -v '^D' | grep '\.py' | \
|
||
|
sed 's/[A-Z][ \t]*//' | \
|
||
|
xargs black 2>&1| \
|
||
|
grep '^reformatted' | \
|
||
|
sed 's/reformatted[ \t]//' | \
|
||
|
xargs git add
|
||
|
|
||
|
else
|
||
|
"Black isn't installed so not formatting python code"
|
||
|
fi
|