This script runs bunx prettier --check against all files
committed in a branch that differ from main (git diff main...HEAD).
Having --diff-filter=AM means "only Added and Modified" (not deleted)
Workflow:
- modify, commit
- check with this script (
bash script.shfrom repo root) - edit last line from
--checkto--writeif wanting to "fix" - push
#!/bin/bash
# Get files modified in current branch compared to main
files=$(git diff main...HEAD --name-only --diff-filter=AM)
if [ -z "$files" ]; then
echo "No modified or added files compared to main."
exit 0
fi
# Filter only files prettier can handle
prettier_files=$(echo "$files" | grep -E '\.(js|jsx|ts|tsx|md|mdx|json|css|scss|html|yaml|yml)$')
if [ -z "$prettier_files" ]; then
echo "No files matching prettier extensions."
exit 0
fi
echo "Running prettier --check on:"
echo "$prettier_files" | sed 's/^/ /'
echo
bunx prettier --check $prettier_files