Skip to content

a smart CLI Git commit message generator using FZF

License

Notifications You must be signed in to change notification settings

ojsef39/commit-oracle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

Commit Oracle

Commit Oracle is a smart Git commit message generator that leverages AI to suggest contextually relevant commit messages based on your staged changes. It integrates seamlessly with your Git workflow and popular tools like LazyGit.

Features

  • Generates 5+ AI-powered commit messages based on your staged Git changes
  • Uses the Conventional Commits format for structured, consistent messages
  • Allows browsing and selection of suggested messages using FZF
  • Supports editing of the selected message before committing
  • Integrates with LazyGit for a smooth workflow

Requirements

  • FZF - fuzzy finder
  • aichat - CLI tool for interacting with OpenAI's ChatGPT and other LLMs

Installation

  1. Clone this repository:

    git clone https://github.com/tfriedel/commit-oracle.git
  2. Add the script to your PATH. Add this line to your ~/.bashrc or ~/.zshrc:

    export PATH=$PATH:/path/to/commit-oracle
  3. Source your updated RC file or restart your terminal.

  4. Install aichat and FZF by following the instructions in the repositories.

Usage

Standalone

Run the script in your Git repository after staging your changes:

commit-oracle.sh

With LazyGit

To use Commit Oracle with LazyGit, add the following to your LazyGit config file (usually located at ~/.config/lazygit/config.yml and for macos at ~/Library/Application\ Support/lazygit/config.yml):

# yaml-language-server: $schema=https://raw.githubusercontent.com/jesseduffield/lazygit/master/schema/config.json
customCommands:
  - key: <c-g>
    description: Pick LLM commit
    loadingText: "waiting for LLM to generate commit messages..."
    command: clear && export EDITOR=nvim && commit-oracle.sh
    context: files
    subprocess: true

Now you can use the <Ctrl-G> shortcut in LazyGit to invoke Commit Oracle.

How It Works

  1. The script extracts the diff of staged changes.
  2. It sends this diff to an LLM, requesting commit message suggestions.
  3. The LLM generates multiple commit messages following the Conventional Commits format.
  4. FZF presents these messages for you to browse and select.
  5. You can edit the selected message in your preferred text editor.
  6. The script commits the changes with your chosen (and possibly edited) message. In case you don't save the message, the script will abort the commit.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

The code is heavily based on the script that "deepanchal" posted here.
This script was based on chhoumann's template.

About

a smart CLI Git commit message generator using FZF

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 100.0%