Skip to content

Instantly share code, notes, and snippets.

@svandragt
Created February 16, 2025 21:08
Show Gist options
  • Save svandragt/99bcab3ab01746d0f1529ae8de8d0964 to your computer and use it in GitHub Desktop.
Save svandragt/99bcab3ab01746d0f1529ae8de8d0964 to your computer and use it in GitHub Desktop.
Git Commit AI logs
#!/usr/bin/env bash
# filename: ~/bin/git-cai
# example: git cai
#
# Copies an AI-generated summary of a commit to the clipboard before opening the commit dialog.
# Requires commitmsg and copy aliases
# uvx llm keys set gemini
# Detect the OS type
if [[ "$OSTYPE" == "darwin"* ]]; then
CLIP_CMD="pbcopy" # macOS clipboard command
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
CLIP_CMD="xsel -ib" # Linux clipboard command
else
echo "Unsupported OS: $OSTYPE" >&2
exit 1
fi
# Generate the commit message and copy it to the clipboard
git diff --staged | uvx --with llm-gemini llm -m gemini-2.0-pro-exp-02-05 -s 'Generate a git commit message for these changes. Avoid overly verbose descriptions or unnecessary details. Start with a short sentence in imperative form, no more than 50 characters long. Then leave an empty line and continue with a more detailed explanation. Write only one sentence for the first part, and two or three sentences at most for the detailed explanation.' | $CLIP_CMD
git commit
@svandragt
Copy link
Author

  1. Requires uv: https://docs.astral.sh/uv/
  2. Requires a Gemini API key (https://aistudio.google.com/), but it works with any other model supported by llm: https://llm.datasette.io/en/stable/

Using uvx means you don't need to install llm or python or the model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment