Git Commit Message AI Script for a shell function called `gcm` that uses an AI model (Gemini) to automatically generate a one-line git commit message from the staged diff. The function allows users to accept, edit, regenerate, or cancel the proposed message before committing. It is designed to be added to a user's `.bashrc` or `.zshrc` file and requires the `llm` CLI utility. ----------------------------------------------------------------------------- AI-powered Git Commit Function Copy paste this gist into your ~/.bashrc or ~/.zshrc to gain the gcm command. It: 1 gets the current staged changed diff 2 sends them to an LLM to write the git commit message 3 allows you to easily accept, edit, regenerate, cancel But - just read and edit the code however you like the llm CLI util is awesome, can get it here: https://llm.datasette.io/en/stable/ Unalias gcm if it exists to prevent conflicts unalias gcm 2 /dev/null Define the AI-powered gcm function using gemini gcm { Function to generate commit message using the gemini model generate commit message { git diff --cached | llm -m gemini-1.5-flash-latest " Below is a diff of all staged changes, coming from the command: \ \ \ git diff --cached \ \ \ Please generate a concise, one-line commit message for these changes." } Function to read user input compatibly with both Bash and Zsh read input { if -n "$ZSH VERSION" ; then echo -n "$1" read -r REPLY else read -p "$1" -r REPLY fi } Main script echo "Generating AI-powered commit message using gemini..." commit message=$ generate commit message while true; do echo -e "\nProposed commit message:" echo "$commit message" read input "Do you want to a ccept, e dit, r egenerate, or c ancel? " choice=$REPLY case "$choice" in a|A if git commit -m "$commit message"; then echo "Changes committed successfully " return 0 else echo "Commit failed. Please check your changes and try again." return 1 fi ;; e|E read input "Enter your commit message: " commit message=$REPLY if -n "$commit message" && git commit -m "$commit message"; then echo "Changes committed successfully with your message " return 0 else echo "Commit failed. Please check your message and try again." return 1 fi ;; r|R echo "Regenerating commit message using gemini..." commit message=$ generate commit message ;; c|C echo "Commit cancelled." return 1 ;; echo "Invalid choice. Please try again." ;; esac done }