#!/bin/sh # adapted from https://prettier.io/docs/en/precommit.html#option-5-shell-script FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g' | grep '.dart$') [ -z "$FILES" ] && exit 0 # Format all selected files echo "$FILES" | xargs dart format # Add back the formatted files to staging echo "$FILES" | xargs git add exit 0