From bd5b513a69882b5664e2792bc008a56d97bc021d Mon Sep 17 00:00:00 2001 From: cyteen Date: Mon, 16 Mar 2026 00:42:13 +0000 Subject: [PATCH] Updated and configured for free ai no-api-key. --- 020_lazycommit.sh | 115 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 94 insertions(+), 21 deletions(-) diff --git a/020_lazycommit.sh b/020_lazycommit.sh index 37574e9..6330c0c 100644 --- a/020_lazycommit.sh +++ b/020_lazycommit.sh @@ -1,37 +1,55 @@ #!/usr/bin/env bash +DEST=${1:-/etc/skel} # Install lazycommit -go install github.com/m7medvision/lazycommit@latest +# go install github.com/m7medvision/lazycommit@latest -# Add Go bin directory to PATH if it doesn't exist -if ! echo "$PATH" | grep -q "$(go env GOPATH)/bin"; then - mkdir -p "${HOME}/.zshrc.d" - - # Write the PATH export with proper escaping - cat >"${HOME}/.zshrc.d/008_lazycommit.zsh" <<'EOF' - # Add Go binaries to PATH - export PATH="${PATH}:${HOME}/go/bin" -EOF - - # Source the new file - source "${HOME}/.zshrc.d/008_lazycommit.zsh" -fi +# # 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 -mkdir -p "${HOME}/.config/.lazycommit" +# LAZYCOMMIT_HOME=${DEST}/.config/ +# mkdir -p "${LAZYCOMMIT_HOME}/lazycommit" # Create the configuration file with default settings -cat >"${HOME}/.config/.lazycommit.yaml" <<'EOF' -active_provider: copilot +cat >"${DEST}/.config/.lazycommit.yaml" <<'EOF' +active_provider: anthropic # default is copilot if a GitHub token is found providers: copilot: - api_key: "$GITHUB_TOKEN" - model: "gpt-4o" + 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" <", "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 +# 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 +# lazycommit commit