portfolio/.githooks/pre-commit

22 lines
493 B
Plaintext
Raw Normal View History

2023-12-13 22:32:55 +00:00
#!/usr/bin/env bash
set -e
STAGED=$(
git --no-pager diff --name-only --no-color --cached --diff-filter=d |
# Remove quotations used to surrounding filenames with special characters.
sed -e "s/^\"//" -e "s/\"$//g"
)
TARGETS=()
while IFS= read -r FILENAME
do
if [[ "$FILENAME" =~ .*\.jsx?$ ]] || [[ "$FILENAME" == .*\.tsx?$ ]]; then
TARGETS+=("${FILENAME}")
fi
done <<< "$STAGED"
if (( ${#TARGETS[@]} )); then
prettier --write "${TARGETS[@]}"
git add "${TARGETS[@]}"
fi