feat: add check-fmt-pre-commit.bash to git hooks
Some checks failed
Check Formatting of Files / Check-Formatting (push) Failing after 25s

This commit is contained in:
Price Hiller 2024-03-16 14:59:19 -05:00
parent 8ec34c10ee
commit 78b3796e68
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB
4 changed files with 27 additions and 3 deletions

View File

@ -28,6 +28,7 @@ in {
home = {
packages = with pkgs;
[
Fmt
nodePackages.prettier
shfmt
bob-nvim
@ -236,7 +237,7 @@ in {
};
git = {
enable = true;
hooks = { pre-commit = ../scripts/check-fmt-git-files.bash; };
hooks = { pre-commit = ../scripts/check-fmt-git-pre-commit.bash; };
userName = "Price Hiller";
userEmail = "price@orion-technologies.io";
aliases = { unstage = "reset HEAD --"; };

View File

@ -41,7 +41,7 @@
defaultPackage.x86_64-linux = home-manager.defaultPackage.x86_64-linux;
targets.genericLinux = { enable = true; };
homeConfigurations.${username} =
home-manager.lib.homeManagerConfiguration {
home-manager.lib.homeManagerConfiguration rec {
pkgs = nixpkgs.legacyPackages.${system};
extraSpecialArgs = {
inherit inputs;
@ -57,6 +57,7 @@
inputs.kanagawa-gtk.overlays.default
inputs.nixgl.overlay
(final: prev: {
Fmt = pkgs.writeScriptBin "Fmt" (builtins.readFile ./scripts/fmt.bash);
waybar = inputs.waybar.packages.${system}.default;
lxappearance = prev.lxappearance.overrideAttrs (oldAttrs: {
postInstall = ''

View File

@ -16,7 +16,7 @@ main() {
fi
done < <(git ls-tree --full-name --full-tree --name-only -r HEAD)
"${root}/scripts/fmt.bash" -- "${files[@]}"
Fmt -- "${files[@]}"
}
main "${@}"

View File

@ -0,0 +1,22 @@
#!/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 "${@}"