From f863bce0fa585e66d58d0095c35eb2e30c22c04c Mon Sep 17 00:00:00 2001 From: anaxios Date: Thu, 8 Aug 2024 01:30:10 -0700 Subject: [PATCH] Now stands as middleware between the git commit command and the default editor. --- aicommit | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/aicommit b/aicommit index a6eb34d..4bed12f 100755 --- a/aicommit +++ b/aicommit @@ -3,7 +3,8 @@ set -e ARGS=("${@-}") -TMP_FILE="/tmp/aicommit" +TMP_FILE="/tmp/aicommit_tmp" + system=$( cat - </dev/null - -hasFlag() { - local flags=("$@") - for var in "${ARGS[@]}"; do - for flag in "${flags[@]}"; do - if [[ ${flag} == "${var}" ]]; then - echo 'true' - return - fi - done - done - echo 'false' -} - if ! diff=$(git diff --cached); then echo "Failed to get diff." exit 1 @@ -41,13 +27,12 @@ message=$( ".message = $(jq -R -s '@json' <<<"${message_cat}")" ) -# trunk-ignore(shellcheck/SC2091) -# trunk-ignore(shellcheck/SC2310) -if $(hasFlag -r --reset); then - if ! curl -s -X POST https://infer.x64.world/reset-conversation >/dev/null; then - echo "Failed to reset conversation." - exit 1 - fi +echo "" +echo "Please wait for AI reponse..." + +if ! curl -s -X POST https://infer.x64.world/reset-conversation >/dev/null; then + echo "Failed to reset conversation." + exit 1 fi curl -s "https://infer.x64.world/chat" \ @@ -55,12 +40,14 @@ curl -s "https://infer.x64.world/chat" \ -H "Content-Type: application/json" \ -d "${message}" | jq -r '.content | gsub("\""; "")' >"${TMP_FILE}" -# trunk-ignore(shellcheck/SC2181) if [[ 0 -ne $? ]]; then echo "Failed to get response." exit 1 fi -git commit -e -m "$(cat "${TMP_FILE}")" && rm "${TMP_FILE}" +cat ".git/COMMIT_EDITMSG" >>"${TMP_FILE}" +cat "${TMP_FILE}" >".git/COMMIT_EDITMSG" -popd >/dev/null +rm "${TMP_FILE}" + +"${EDITOR}" "$@"