Skip to content

Instantly share code, notes, and snippets.

@b-barry
Forked from RafalWilinski/gac.sh
Created December 19, 2024 09:31
Show Gist options
  • Save b-barry/80367211a502665cc4e7a8b636efb394 to your computer and use it in GitHub Desktop.
Save b-barry/80367211a502665cc4e7a8b636efb394 to your computer and use it in GitHub Desktop.
Generating commit messages using `llm` CLI in command line
# Function to generate commit message using LLM
generate_commit() {
git add .
# Get the staged changes
DIFF=$(git diff --cached)
if [ -z "$DIFF" ]; then
echo "No staged changes found. Please stage your changes first using 'git add'"
return 1
fi
# Generate commit message using LLM
COMMIT_MSG=$(echo "$DIFF" | llm "Generate a concise commit message (first line) and detailed description (separated by blank line) based on these changes. Follow conventional commits format. Git diff: ")
if [ -z "$COMMIT_MSG" ]; then
echo "Failed to generate commit message"
return 1
fi
# Commit with the generated message
git commit -m "$COMMIT_MSG"
}
# Alias for the function
alias gac='generate_commit'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment