跳到正文
GitHub·· 5 天前AI 评分22

gitsloth:用 OpenAI 生成 Conventional Commit 的 Rust CLI

saccofrancesco/gitsloth

AI 导读

gitsloth 是一个轻量 Rust CLI,读取暂存的 Git diff、分支名和状态,调用 OpenAI 生成一条或多条 Conventional Commit 信息,供用户选择后提交或复制到剪贴板。它支持 -g 指定生成条数、-a 暂存全部改动、-c 复制而非提交、-y 跳过单条确认,依赖仅 Rust 标准库加 HTTP/JSON crate,采用 MIT 许可。

正文

gitsloth: AI-Powered Git Commit Messages

A lightweight Rust CLI that generates clean, Conventional Commit messages from your staged Git changes using OpenAI.

Contributors Forks Stars Version

TL;DR • Key Features • Quickstart • License


TL;DR

gitsloth reads your staged Git diff (plus branch name and status), asks OpenAI for one or more Conventional Commit messages, lets you select one, then commits it (or copies it to your clipboard).


Why gitsloth

  • Writing high-quality commit messages is repetitive
  • Conventional Commits are useful but often tedious
  • This tool automates the process while staying minimal

Key Features

  • AI-generated Conventional Commit messages
  • Multiple suggestions with interactive selection
  • Git context: branch, short status, staged diff
  • Optional stage-all flow (-a)
  • Optional clipboard flow (-c)
  • Optional confirmation bypass for single message (-y)
  • Minimal dependency strategy (Rust stdlib + only HTTP/JSON crates)

Quickstart

Install prebuilt binary (recommended)

curl -fsSL https://raw.githubusercontent.com/saccofrancesco/gitsloth/main/install.sh | sh

Installer behavior:

  • detects macOS/Linux and CPU architecture automatically
  • downloads the matching release asset from GitHub Releases
  • installs to /usr/local/bin when writable, otherwise ~/.local/bin
  • adds the install directory to your shell profile when needed

Optional overrides:

# Install a specific tag
GITSLOTH_VERSION=v1.4.1 curl -fsSL https://raw.githubusercontent.com/saccofrancesco/gitsloth/main/install.sh | sh

# Install to a custom directory
GITSLOTH_INSTALL_DIR="$HOME/bin" curl -fsSL https://raw.githubusercontent.com/saccofrancesco/gitsloth/main/install.sh | sh

Uninstall

curl -fsSL https://raw.githubusercontent.com/saccofrancesco/gitsloth/main/uninstall.sh | sh

Optional override:

# Remove from a custom directory too
GITSLOTH_INSTALL_DIR="$HOME/bin" curl -fsSL https://raw.githubusercontent.com/saccofrancesco/gitsloth/main/uninstall.sh | sh

Build from source

git clone https://github.com/saccofrancesco/gitsloth.git
cd gitsloth
cargo build --release

Binary path:

./target/release/gitsloth

Setup

export OPENAI_API_KEY=your_api_key_here

Usage

# Generate a single commit message (with confirmation)
./target/release/gitsloth

# Generate multiple messages and choose one
./target/release/gitsloth -g 3

# Stage everything before generating
./target/release/gitsloth -a

# Copy selected message to clipboard instead of committing
./target/release/gitsloth -c

# Skip confirmation when generating a single message
./target/release/gitsloth -y

# Print installed version
./target/release/gitsloth -v

Flags

Flag Shorthand Description
--generate -g Number of commit messages to generate
--all -a Stage all changes before generating
--clipboard -c Copy the selected message instead of committing
--yes -y Skip confirmation prompt for single message
--version -v Print gitsloth version

Examples

Single message (default)

$ ./target/release/gitsloth
⣾ Generating commit messages...
Proposed message:
 feat: add clipboard support and structured git context

Confirm? (y/n):

Multiple messages

$ ./target/release/gitsloth -g 3
⣾ Generating commit messages...
Generated messages:
1) feat: add clipboard support
2) feat: improve commit generation prompt context
3) refactor: simplify commit selection flow

Select (0 to abort):

Development

cargo fmt
cargo clippy -- -D warnings
cargo test

Emailware

gitsloth is emailware. If you find it useful, I would like to hear from you.


License

This project is licensed under the MIT License.


GitHub @saccofrancesco

来源:GitHub · github.com