From 7849e3fcdd1e160723f63097abdad9e19c446bb0 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Sun, 3 Dec 2023 11:24:45 -0700 Subject: [PATCH] Simply pre-commit hooks. --- specs/clang/template/.githooks/pre-commit | 10 ++++------ specs/mix/template/.githooks/pre-commit | 10 ++++------ specs/nodejs/template/.githooks/pre-commit | 10 ++++------ specs/phoenix/template/.githooks/pre-commit | 20 +++++++------------- specs/poetry/template/.githooks/pre-commit | 10 ++++------ 5 files changed, 23 insertions(+), 37 deletions(-) diff --git a/specs/clang/template/.githooks/pre-commit b/specs/clang/template/.githooks/pre-commit index c736197..8de71f8 100755 --- a/specs/clang/template/.githooks/pre-commit +++ b/specs/clang/template/.githooks/pre-commit @@ -1,13 +1,11 @@ #!/usr/bin/env bash set -e -filesToFormat=$( +FORMAT_FILES=$( git --no-pager diff --name-status --no-color --cached | \ awk '$1 != "D" && $2 ~ /\.c$|\.h$/ {print $NF}' ) -for path in $filesToFormat -do - clang-format -i "$path" - git add "$path" -done +clang-format -i "$FORMAT_FILES" + +git add "$FORMAT_FILES" diff --git a/specs/mix/template/.githooks/pre-commit b/specs/mix/template/.githooks/pre-commit index 90300f5..12eaaac 100755 --- a/specs/mix/template/.githooks/pre-commit +++ b/specs/mix/template/.githooks/pre-commit @@ -1,13 +1,11 @@ #!/usr/bin/env bash set -e -filesToFormat=$( +FORMAT_FILES=$( git --no-pager diff --name-status --no-color --cached | \ awk '$1 != "D" && $2 ~ /\.exs?$/ {print $NF}' ) -for path in $filesToFormat -do - mix format "$path" - git add "$path" -done +mix format "$FORMAT_FILES" + +git add "$FORMAT_FILES" diff --git a/specs/nodejs/template/.githooks/pre-commit b/specs/nodejs/template/.githooks/pre-commit index 4b2c4ca..b0d95f1 100755 --- a/specs/nodejs/template/.githooks/pre-commit +++ b/specs/nodejs/template/.githooks/pre-commit @@ -1,13 +1,11 @@ #!/usr/bin/env bash set -e -filesToFormat=$( +FORMAT_FILES=$( git --no-pager diff --name-status --no-color --cached | \ awk '$1 != "D" && $2 ~ /\.jsx?$|\.tsx?$/ {print $NF}' ) -for path in $filesToFormat -do - prettier --write "$path" - git add "$path" -done +prettier --write "$FORMAT_FILES" + +git add "$FORMAT_FILES" diff --git a/specs/phoenix/template/.githooks/pre-commit b/specs/phoenix/template/.githooks/pre-commit index 1ddbda9..1fef035 100755 --- a/specs/phoenix/template/.githooks/pre-commit +++ b/specs/phoenix/template/.githooks/pre-commit @@ -1,24 +1,18 @@ #!/usr/bin/env bash set -e -mixFiles=$( +MIX_FILES=$( git --no-pager diff --name-status --no-color --cached | \ awk '$1 != "D" && $2 ~ /\.exs?$/ {print $NF}' ) -for path in $mixFiles -do - mix format "$path" - git add "$path" -done - -webFiles=$( +WEB_FILES=$( git --no-pager diff --name-status --no-color --cached | \ awk '$1 != "D" && $2 ~ /\.jsx?$|\.tsx?$/ {print $NF}' ) -for path in $webFiles -do - prettier --write "$path" - git add "$path" -done +mix format "$MIX_FILES" + +prettier --write "$WEB_FILES" + +git add "$MIX_FILES" "$WEB_FILES" diff --git a/specs/poetry/template/.githooks/pre-commit b/specs/poetry/template/.githooks/pre-commit index 13e04f1..4f0d595 100644 --- a/specs/poetry/template/.githooks/pre-commit +++ b/specs/poetry/template/.githooks/pre-commit @@ -1,13 +1,11 @@ #!/usr/bin/env bash set -e -filesToFormat=$( +FORMAT_FILES=$( git --no-pager diff --name-status --no-color --cached | \ awk '$1 != "D" && $2 ~ /\.py$/ {print $NF}' ) -for path in $filesToFormat -do - black --quiet "$path" - git add "$path" -done +black --quiet "$FORMAT_FILES" + +git add "$FORMAT_FILES"