Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Ridermansb/4b77aea21c09e754baba1de59762a0ce to your computer and use it in GitHub Desktop.
Save Ridermansb/4b77aea21c09e754baba1de59762a0ce to your computer and use it in GitHub Desktop.
Lazygit Configuration + Raycast AI Commit Message Generator
- key: "<c-d>"
context: "files"
description: "Generate Commit Message with Raycast"
prompts:
- type: "input"
title: "Explain the changes"
key: "Explain"
initialValue: ""
- type: 'menu'
key: "Language"
title: "Language?"
options:
- value: 'English'
- value: 'Português'
- type: 'menu'
title: "Commit Convention?"
key: "Convention"
options:
- value: 'git-commit'
- value: 'git-conventional-commit'
command: 'git diff --cached -U4 | pbcopy && open "raycast://ai-commands/generates-{{.Form.Convention}}?arguments=\"{{.Form.Explain | quote}}\"&arguments=\"{{.SelectedLocalBranch.Name}}\"&arguments=\"{{.Form.Language | quote}}\""'

This configuration enables you to generate high-quality, AI-powered commit messages directly from Lazygit, leveraging Raycast’s AI commands. It streamlines the process by copying your staged diff, prompting you for context, and opening Raycast to generate a commit message in your preferred language and style.

How It Works

  1. Trigger the Command in Lazygit

    • In the Lazygit files view, press Ctrl+D (<c-d>).
    • This runs a custom command defined in your lazygit/config.yml.
  2. Prompt Sequence

    • Explain the changes: You’re prompted to briefly describe what you changed.
    • Choose language: Select your preferred language for the commit message (English or Português).
    • Choose convention: Select the commit message style (standard git-commit or git-conventional-commit).
  3. Copy Diff to Clipboard

    • The command copies the current staged diff (git diff --cached -U4) to your clipboard using pbcopy.
  4. Open Raycast AI Command

    • Lazygit opens a Raycast AI Command via a Deeplink, passing your summary, branch name, and language as arguments.
    • Raycast receives the clipboard diff and your inputs, then generates a commit message using AI.

What Each Step Does

  • git diff --cached -U4 | pbcopy: Copies the staged changes (with context) to your clipboard.
  • Prompts: Collects your summary, language, and commit style.
  • Raycast Deeplink: Opens a Raycast AI Command, passing your inputs as arguments. Raycast then uses the clipboard diff and your context to generate a commit message.

Requirements

  • Lazygit: With custom commands enabled.
  • Raycast: With the relevant AI Command set up to accept arguments and generate commit messages.
  • macOS: Uses pbcopy and open commands.

Benefits

  • Fast: No need to leave Lazygit or manually write commit messages.
  • Consistent: Enforces your preferred commit style and language.
  • AI-powered: Leverages Raycast’s AI to summarize your changes accurately.

You can find more details on https://ridermansb.dev/article/83307/how-i-use-ai-raycast-and-lazygit-to-help-me-write-better-commit-messages

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