Files
git.taskfile.build/bin/commit-with-llm
T
Janik von Rotz 9ed49da6df feat(aliases): add command aliases for all bin scripts using first-letter shorthand
- Implement cwl() alias function in bin/commit-with-llm to enable `t cwl` shorthand
- Create prompt template for alias implementation task with proper frontmatter fields
- Follow consistent alias pattern using first letters of command names
- Document alias implementation approach in task prompt for future reference
2026-07-08 15:10:59 +02:00

51 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
commit-with-llm() {
mkdir -p tmp
local prompt_file="tmp/llm_update"
echo -e "\nWrite prompt to $prompt_file."
cat << EOF > "$prompt_file"
Look at the git log and the git diff below and reply with a git commit message matching the changes and style of the log.
The commit message must comply with the conventional commits specification. Reply with the commit message only.
<<< git log -n 5 --pretty=format:"%ci: %B" >>>
$(git log -n 5 --pretty=format:"%ci: %B")
<<< git diff --staged >>>
$(git diff --staged)
EOF
# Run the llm command
echo -e "Send prompt with staged git diff and wait for the response of the $(llm models | sed -n 's/^Default: //p') LLM."
local result=$(cat "$prompt_file" | llm)
# Check if result is empty
if [[ -z "$result" ]]; then
echo "No response from the model. Exiting."
exit 1
fi
# Save the result to a file
local result_file="tmp/llm_update_result"
echo "$result" > "$result_file"
echo -e "Saved response to $result_file.\n"
# Show a preview of result file
less "$result_file"
# Ask for confirmation before updating files
read -p "Do you want to commit or edit before commit the message? (y/e/n): " confirm
if [[ ! "$confirm" =~ ^[YyEe]$ ]]; then
exit 0
fi
git commit -m "$result"
if [[ "$confirm" =~ ^[Ee]$ ]]; then
git commit --amend
fi
}
cwl() {
commit-with-llm
}