dots/scripts/check-fmt-git-pre-commit.bash
Price Hiller 78b3796e68
Some checks failed
Check Formatting of Files / Check-Formatting (push) Failing after 25s
feat: add check-fmt-pre-commit.bash to git hooks
2024-03-16 14:59:19 -05:00

23 lines
447 B
Bash

#!/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)
Fmt -- "${files[@]}"
}
main "${@}"