dots/scripts/check-fmt-git-pre-commit.bash
Price Hiller 07cf91ca0b
All checks were successful
Check Formatting of Files / Check-Formatting (push) Successful in 45s
refactor: improve handling of Fmt command
2024-03-16 15:26:34 -05:00

25 lines
483 B
Bash
Executable File

#!/usr/bin/env -S nix --extra-experimental-features "flakes nix-command" shell nixpkgs#bash nixpkgs#git --command bash
# vim: ft=sh
set -euo pipefail
main() {
local root
root="$(git rev-parse --show-toplevel)"
local files=()
while IFS= read -r file; do
local fpath="${root}/${file}"
if [[ -r "${fpath}" ]]; then
files+=("${fpath}")
fi
done < <(git diff --name-only --staged --diff-filter=d)
if ((${#files[@]} > 0)); then
Fmt -- "${files[@]}"
fi
}
main "${@}"