From a08e8e9a7475bb9d2fe6e4a173a3bc42bceddd16 Mon Sep 17 00:00:00 2001 From: Sonny Date: Sat, 24 Aug 2019 19:19:38 +0200 Subject: [PATCH 1/2] Use user installed binaries --- pre-commit.d/autoflake.sh | 2 +- pre-commit.d/isort.sh | 2 +- pre-commit.d/prettier.sh | 2 +- pre-commit.d/yapf.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pre-commit.d/autoflake.sh b/pre-commit.d/autoflake.sh index 7e4ec3f..f28b018 100755 --- a/pre-commit.d/autoflake.sh +++ b/pre-commit.d/autoflake.sh @@ -3,7 +3,7 @@ FILES=$(git diff --cached --name-only --diff-filter=ACM "*.py" | sed 's| |\\ |g' if [ ! -z "$FILES" ]; then # Format all selected files - echo "$FILES" | xargs -I {} /bin/bash -c "/home/sonny/.local/bin/autoflake --in-place --remove-unused-variables {}" + echo "$FILES" | xargs -I {} /bin/bash -c "$HOME/.local/bin/autoflake --in-place --remove-unused-variables {}" if [ $? -ne 0 ]; then exit 1 diff --git a/pre-commit.d/isort.sh b/pre-commit.d/isort.sh index 09757c0..2553b36 100755 --- a/pre-commit.d/isort.sh +++ b/pre-commit.d/isort.sh @@ -3,7 +3,7 @@ FILES=$(git diff --cached --name-only --diff-filter=ACM "*.py" | sed 's| |\\ |g' if [ ! -z "$FILES" ]; then # Format all selected files - echo "$FILES" | xargs ./env/bin/isort + echo "$FILES" | xargs $HOME/.local/bin/isort if [ $? -ne 0 ]; then exit 1 diff --git a/pre-commit.d/prettier.sh b/pre-commit.d/prettier.sh index 86670c5..68f1bb2 100755 --- a/pre-commit.d/prettier.sh +++ b/pre-commit.d/prettier.sh @@ -3,7 +3,7 @@ FILES=$(git diff --cached --name-only --diff-filter=ACM "*.js" | sed 's| |\\ |g' if [ ! -z "$FILES" ]; then # Prettify all selected files - echo "$FILES" | xargs ./node_modules/.bin/prettier --write + echo "$FILES" | xargs prettier --write if [ $? -ne 0 ]; then exit 1 diff --git a/pre-commit.d/yapf.sh b/pre-commit.d/yapf.sh index df06a90..1d25d4d 100755 --- a/pre-commit.d/yapf.sh +++ b/pre-commit.d/yapf.sh @@ -3,7 +3,7 @@ FILES=$(git diff --cached --name-only --diff-filter=ACM "*.py" | sed 's| |\\ |g' if [ ! -z "$FILES" ]; then # Format all selected files - echo "$FILES" | xargs ./env/bin/yapf --in-place --verbose --style=./yapf.conf + echo "$FILES" | xargs $HOME/.local/bin/yapf --in-place --verbose --style=./yapf.conf if [ $? -ne 0 ]; then exit 1 From c41085a2644795eb42df627ee16ae15bde62410f Mon Sep 17 00:00:00 2001 From: Sonny Date: Sat, 24 Aug 2019 19:20:18 +0200 Subject: [PATCH 2/2] Add black formatting hook --- pre-commit.d/black.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 pre-commit.d/black.sh diff --git a/pre-commit.d/black.sh b/pre-commit.d/black.sh new file mode 100644 index 0000000..50acaf5 --- /dev/null +++ b/pre-commit.d/black.sh @@ -0,0 +1,16 @@ +#!/bin/bash +FILES=$(git diff --cached --name-only --diff-filter=ACM "*.py" | sed 's| |\\ |g') + +LINE_LENGTH=90 + +if [ ! -z "$FILES" ]; then + # Format all selected files + echo "$FILES" | xargs $HOME/.local/bin/black -l $LINE_LENGTH + + if [ $? -ne 0 ]; then + exit 1 + fi + + # Add back the modified files to staging + echo "$FILES" | xargs git add +fi