From 0c35e521365c7341f2482c90032d0c2de1edb606 Mon Sep 17 00:00:00 2001 From: uttarayan21 Date: Wed, 20 Aug 2025 01:18:27 +0530 Subject: [PATCH] feat(scripts): add prepare-commit-msg hook installation script --- home/scripts.nix | 8 ++++++++ scripts/prepare-commit-msg | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 scripts/prepare-commit-msg diff --git a/home/scripts.nix b/home/scripts.nix index 1c30a113..27afa2fa 100644 --- a/home/scripts.nix +++ b/home/scripts.nix @@ -32,6 +32,14 @@ in { exec $EDITOR "$1" ''; }) + ( + pkgs.writeShellApplication { + name = "git-install-prepare-commit-msg"; + text = '' + cp ${../scripts/prepare-commit-msg} .git/hooks/prepare-commit-msg + ''; + } + ) (mkScript ../scripts/yt-dlp.sh (with pkgs; [yt-dlp])) (mkScript ../scripts/autossh.sh (with pkgs; [autossh openssh])) ]; diff --git a/scripts/prepare-commit-msg b/scripts/prepare-commit-msg new file mode 100755 index 00000000..2fb94e8c --- /dev/null +++ b/scripts/prepare-commit-msg @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +if [[ -z "$COMMIT_SOURCE" ]] +then + DIFF_OUTPUT=$(git diff --cached) + AI_CHAT_OUTPUT=$(echo "$DIFF_OUTPUT" | aichat --role %git-commit%) + CURRENT_MSG=$(cat "$COMMIT_MSG_FILE") + + { + echo "$AI_CHAT_OUTPUT" + echo + echo "$CURRENT_MSG" + } > "$COMMIT_MSG_FILE" +fi