Skip to content

Instantly share code, notes, and snippets.

@sergebulaev
Last active November 26, 2024 03:01
Show Gist options
  • Select an option

  • Save sergebulaev/e8f56279dbab37ae3b8539363cd363fa to your computer and use it in GitHub Desktop.

Select an option

Save sergebulaev/e8f56279dbab37ae3b8539363cd363fa to your computer and use it in GitHub Desktop.
# -----------------------------------------------------------------------------
# AI-powered Diff Summary Function
# Add this to your ~/.bashrc or ~/.zshrc to gain the `diff` command. It:
# 1) Checks if there are any staged changes
# 2) Summarizes what was added and removed from the staged changes
# 3) Outputs a concise summary directly in the terminal
#
# Requirements:
# - Git
# - LLM CLI utility (https://llm.datasette.io/en/stable/)
# - GPT-4-mini model available for LLM
diffllm() {
# Check if there are any staged changes
if [ -z "$(git diff --cached)" ]; then
echo "No staged changes to analyze."
return 1
fi
# Generate a concise summary of the staged changes
echo "Analyzing staged changes for a quick summary..."
git diff --cached | llm -m 4o-mini "
Below is a diff of all staged changes. Provide a quick, text-only summary of the changes in the format:
Removed:
- Key point 1
- Key point 2
Added:
- Key point 1
- Key point 2
If there are no changes in a category, omit it entirely. Be as concise as possible and focus only on the most notable modifications."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment