#!/usr/bin/env bash DEST=${1:-/etc/skel} # Install lazycommit # go install github.com/m7medvision/lazycommit@latest # # Add once – usually already present if you installed Go via official method # if [[ ":$PATH:" != *":$HOME/go/bin:"* ]]; then # echo 'export PATH="$HOME/go/bin:$PATH"' >> ~/.zshrc # export PATH="$HOME/go/bin:$PATH" # fi # Create the configuration directory # LAZYCOMMIT_HOME=${DEST}/.config/ # mkdir -p "${LAZYCOMMIT_HOME}/lazycommit" # Create the configuration file with default settings cat >"${DEST}/.config/.lazycommit.yaml" <<'EOF' active_provider: anthropic # default is copilot if a GitHub token is found providers: copilot: api_key: "$GITHUB_TOKEN" # Uses GitHub token; token is exchanged internally model: "gpt-4o" # or "openai/gpt-4o"; both accepted # endpoint_url: "https://api.githubcopilot.com" # Optional - uses default if not specified openai: api_key: "$OPENAI_API_KEY" model: "gpt-4o" # endpoint_url: "https://api.openai.com/v1" # Optional - uses default if not specified anthropic: model: "claude-haiku-4-5" # Uses Claude Code CLI - no API key needed num_suggestions: 10 # Number of commit suggestions to generate EOF # Prompt templates and message configurations. cat >"${DEST}/.config/.lazycommit.prompts.yaml" <" # ctrl + a # description: "Pick AI commit" # command: 'echo "{{.Form.Msg}}" > .git/COMMIT_EDITMSG && nvim .git/COMMIT_EDITMSG && [ -s .git/COMMIT_EDITMSG ] && git commit -F .git/COMMIT_EDITMSG || echo "Commit message is empty, commit aborted."' # context: "files" # subprocess: true # prompts: # - type: "menuFromCommand" # title: "AI Commits" # key: "Msg" # command: "bunx @m7medvision/lazycommit@latest" # filter: '^(?P\d+)\.\s(?P.+)$' # valueFormat: "{{ .message }}" # labelFormat: "{{ .number }}: {{ .message | green }}" # Check for the the existance of lazygit config.yml # yq e -i '.customCommands += [{"key": "", "description": "Pick AI commit", "context": "files", "subprocess": true, "loadingText": "Generating commit message...", "prompts": [{"type": "menuFromCommand", "title": "AI Generated Commits", "key": "Msg", "command": "bunx @m7medvision/lazycommit@latest --list", "filter": "^(?P\\d+)\\.\\s(?P.+)$", "valueFormat": "{{ .message }}", "labelFormat": "{{ .number }}: {{ .message | green }}"}], "command": "echo \"{{index .PromptResponses 0}}\" > .git/COMMIT_EDITMSG && nvim .git/COMMIT_EDITMSG && if [ -s .git/COMMIT_EDITMSG ]; then git commit -F .git/COMMIT_EDITMSG; else echo \"Commit message is empty, commit aborted.\" && rm .git/COMMIT_EDITMSG; fi"}]' \ # "${HOME}/.config/lazygit/config.yml" # Write a confguration for lazycommmit in lazygit. CONFIG_ROOT="${DEST}/.config/lazygit" EXTRAS_DIR="${CONFIG_ROOT}/extras" mkdir -p "${EXTRAS_DIR}" conf_print_LC_LD-Config() { cat <<'EOF' customCommands: # Quick commit without editing (direct accept) - key: "" description: "Pick AI commit & commit immediately" context: "files" loadingText: "Generating commit suggestions..." subprocess: true command: 'git commit -m "{{.Form.Msg}}"' prompts: - type: "menuFromCommand" title: "AI Generated Commits" key: "Msg" command: "lazycommit commit" filter: '^(?P.+)$' valueFormat: "{{ .raw }}" labelFormat: "{{ .raw | green }}" # Edit before commit (your original style, but updated) - key: "" description: "Pick AI commit (edit before commit)" context: "files" loadingText: "Generating commit suggestions..." subprocess: true command: | bash -c 'msg="{{.Form.Msg}}" echo "$msg" > .git/COMMIT_EDITMSG ${EDITOR:-nvim} .git/COMMIT_EDITMSG if [ -s .git/COMMIT_EDITMSG ]; then git commit -F .git/COMMIT_EDITMSG else echo "Commit message empty → aborted." rm -f .git/COMMIT_EDITMSG fi' prompts: - type: "menuFromCommand" title: "AI Generated Commits" key: "Msg" command: "lazycommit commit" filter: '^(?P.+)$' valueFormat: "{{ .raw }}" labelFormat: "{{ .raw | green }}" EOF } conf_print_LC_LD-Config | tee "${EXTRAS_DIR}/20-lazycommit.yml" # Verify the installation echo "Current PATH entries:" echo "$PATH" | tr ':' '\n' | grep '/go/bin' # Test lazycommit # lazycommit commit