From 8d1573ad158acab903fed9da1c0b60e0efb37314 Mon Sep 17 00:00:00 2001 From: Matheus Lima Date: Fri, 11 Jul 2025 14:18:39 -0300 Subject: [PATCH 1/4] Solving env vars --- tmp/test.zsh | 1 + zsh-git-ai.zsh | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tmp/test.zsh diff --git a/tmp/test.zsh b/tmp/test.zsh new file mode 100644 index 0000000..d5c70b3 --- /dev/null +++ b/tmp/test.zsh @@ -0,0 +1 @@ +SCRIPT_DIR="${0:A:h}"; echo "Script dir: $SCRIPT_DIR" diff --git a/zsh-git-ai.zsh b/zsh-git-ai.zsh index 8543414..0fe05e0 100644 --- a/zsh-git-ai.zsh +++ b/zsh-git-ai.zsh @@ -3,7 +3,29 @@ # Git Commit AI - Generate commit messages with AI providers # Get the directory where this script is located -SCRIPT_DIR="${0:A:h}" +# Try multiple methods to find the script directory +if [[ -n "${BASH_SOURCE[0]}" ]]; then + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +elif [[ -n "${(%):-%x}" ]]; then + # ZSH-specific: %x expands to the name of the file being sourced + SCRIPT_DIR="${${(%):-%x}:A:h}" +elif [[ -n "$0" ]] && [[ "$0" != "zsh" ]] && [[ "$0" != "-zsh" ]] && [[ "$0" != "/bin/zsh" ]] && [[ "$0" != "/usr/bin/zsh" ]]; then + SCRIPT_DIR="${0:A:h}" +else + # Fallback: try to find the script in common locations + for dir in ~/Apps/zsh-git-ai ~/.oh-my-zsh/custom/plugins/zsh-git-ai /opt/homebrew/share/zsh-git-ai /usr/local/share/zsh-git-ai; do + if [[ -f "$dir/zsh-git-ai.zsh" ]]; then + SCRIPT_DIR="$dir" + break + fi + done +fi + +# Verify we found the script directory +if [[ -z "$SCRIPT_DIR" ]] || [[ ! -d "$SCRIPT_DIR/lib/providers" ]]; then + echo "Error: Could not determine script directory. Please check your installation." >&2 + return 1 +fi # Default provider ZSH_GIT_AI_PROVIDER="${ZSH_GIT_AI_PROVIDER:-anthropic}" From 427c7a01aab672de5e413243e85521f199036f81 Mon Sep 17 00:00:00 2001 From: Matheus Lima Date: Fri, 11 Jul 2025 14:32:19 -0300 Subject: [PATCH 2/4] Rename zsh-git-ai.zsh to plugin.zsh and update references --- CLAUDE.md | 2 +- CONTRIBUTING.md | 6 ++++-- INSTALL.md | 24 ++++++++++++------------ README.md | 4 ++-- tests/main.test.zsh | 8 ++++---- zsh-git-ai.zsh => zsh-git-ai.plugin.zsh | 24 +----------------------- 6 files changed, 24 insertions(+), 44 deletions(-) rename zsh-git-ai.zsh => zsh-git-ai.plugin.zsh (76%) diff --git a/CLAUDE.md b/CLAUDE.md index 7ce7b8b..9d47634 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -57,7 +57,7 @@ When adding/modifying AI providers: ### Common Tasks - **Adding a new provider**: Copy existing provider pattern, add tests - **Modifying commit generation**: Update provider logic and test with various diff formats -- **Changing main script logic**: Update `zsh-git-ai.zsh` and test in `tests/main.test.zsh` +- **Changing main script logic**: Update `zsh-git-ai.plugin.zsh` and test in `tests/main.test.zsh` ### Important Notes - This is a shell-only project - no Node.js, Python, or other runtimes diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e6381dd..92a26f2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,7 +15,7 @@ That's it! We'll help you with the rest. ```bash # Try out your changes -source zsh-git-ai.zsh +source zsh-git-ai.plugin.zsh # Test with a real commit git add some-file @@ -44,8 +44,10 @@ Just follow the existing style you see in the codebase. When in doubt: To test your changes: ```bash -# 1. Source the plugin +# 1. Source the plugin (both work for backward compatibility) source zsh-git-ai.zsh +# or +source zsh-git-ai.plugin.zsh # 2. Create some test changes echo "test" > test.txt diff --git a/INSTALL.md b/INSTALL.md index 243f717..1eb4327 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -19,7 +19,7 @@ brew tap matheusml/zsh-git-ai brew install zsh-git-ai # Add to your .zshrc -echo "source $(brew --prefix)/share/zsh-git-ai/zsh-git-ai.zsh" >> ~/.zshrc +echo "source $(brew --prefix)/share/zsh-git-ai/zsh-git-ai.plugin.zsh" >> ~/.zshrc # Set your API key echo 'export ANTHROPIC_API_KEY="your-api-key-here"' >> ~/.zshrc @@ -35,7 +35,7 @@ source ~/.zshrc git clone https://github.com/matheusml/zsh-git-ai ~/.zsh-git-ai # Add to your .zshrc -echo "source ~/.zsh-git-ai/zsh-git-ai.zsh" >> ~/.zshrc +echo "source ~/.zsh-git-ai/zsh-git-ai.plugin.zsh" >> ~/.zshrc # Set your API key echo 'export ANTHROPIC_API_KEY="your-api-key-here"' >> ~/.zshrc @@ -56,7 +56,7 @@ brew tap matheusml/zsh-git-ai brew install zsh-git-ai # Add to your shell configuration -echo "source $(brew --prefix)/share/zsh-git-ai/zsh-git-ai.zsh" >> ~/.zshrc +echo "source $(brew --prefix)/share/zsh-git-ai/zsh-git-ai.plugin.zsh" >> ~/.zshrc # Reload shell source ~/.zshrc @@ -83,7 +83,7 @@ brew untap matheusml/zsh-git-ai git clone https://github.com/matheusml/zsh-git-ai ~/Apps/zsh-git-ai # Source in your .zshrc -echo "source ~/Apps/zsh-git-ai/zsh-git-ai.zsh" >> ~/.zshrc +echo "source ~/Apps/zsh-git-ai/zsh-git-ai.plugin.zsh" >> ~/.zshrc # Reload source ~/.zshrc @@ -122,14 +122,14 @@ zplug "matheusml/zsh-git-ai" ```bash # Download the script directly -curl -o ~/.zsh-git-ai.zsh \ - https://raw.githubusercontent.com/matheusml/zsh-git-ai/main/zsh-git-ai.zsh +curl -o ~/.zsh-git-ai.plugin.zsh \ + https://raw.githubusercontent.com/matheusml/zsh-git-ai/main/zsh-git-ai.plugin.zsh # Make it executable -chmod +x ~/.zsh-git-ai.zsh +chmod +x ~/.zsh-git-ai.plugin.zsh # Source it -echo "source ~/.zsh-git-ai.zsh" >> ~/.zshrc +echo "source ~/.zsh-git-ai.plugin.zsh" >> ~/.zshrc source ~/.zshrc ``` @@ -284,7 +284,7 @@ echo $SHELL # Should show /bin/zsh or similar 2. Verify source path: ```bash -ls -la ~/.zsh-git-ai/zsh-git-ai.zsh # File should exist +ls -la ~/.zsh-git-ai/zsh-git-ai.plugin.zsh # File should exist ``` 3. Check .zshrc: @@ -318,7 +318,7 @@ curl -X POST https://api.anthropic.com/v1/messages \ ### Permission Denied ```bash -chmod +x ~/.zsh-git-ai/zsh-git-ai.zsh +chmod +x ~/.zsh-git-ai/zsh-git-ai.plugin.zsh ``` ### Conflicts with Other Plugins @@ -334,7 +334,7 @@ alias | grep git # Check aliases 2. Load order matters in .zshrc: ```bash # Load zsh-git-ai after other git plugins -source ~/.zsh-git-ai/zsh-git-ai.zsh +source ~/.zsh-git-ai/zsh-git-ai.plugin.zsh ``` ## Uninstallation @@ -389,7 +389,7 @@ echo 'alias update-zsh-git-ai="cd ~/.zsh-git-ai && git pull && cd - && source ~/ git clone https://github.com/matheusml/zsh-git-ai /custom/path/zsh-git-ai # Source from custom path -echo "source /custom/path/zsh-git-ai/zsh-git-ai.zsh" >> ~/.zshrc +echo "source /custom/path/zsh-git-ai/zsh-git-ai.plugin.zsh" >> ~/.zshrc ``` > 📚 **For more advanced configuration options**, including: diff --git a/README.md b/README.md index 66314b5..0f9d41d 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ brew tap matheusml/zsh-git-ai brew install zsh-git-ai # 2. Add to your shell -echo "source $(brew --prefix)/share/zsh-git-ai/zsh-git-ai.zsh" >> ~/.zshrc +echo "source $(brew --prefix)/share/zsh-git-ai/zsh-git-ai.plugin.zsh" >> ~/.zshrc # 3. Set up your API key export ANTHROPIC_API_KEY="your-api-key-here" @@ -63,7 +63,7 @@ git commit # No -m needed! ```bash # 1. Clone the repository git clone https://github.com/matheusml/zsh-git-ai ~/.zsh-git-ai -echo "source ~/.zsh-git-ai/zsh-git-ai.zsh" >> ~/.zshrc +echo "source ~/.zsh-git-ai/zsh-git-ai.plugin.zsh" >> ~/.zshrc # 2. Set up your API key export ANTHROPIC_API_KEY="your-api-key-here" diff --git a/tests/main.test.zsh b/tests/main.test.zsh index 7447a60..a0c6d1b 100644 --- a/tests/main.test.zsh +++ b/tests/main.test.zsh @@ -7,7 +7,7 @@ source "${0:A:h}/test_helper.zsh" test_default_provider() { setup_test_env unset ZSH_GIT_AI_PROVIDER - source "$PLUGIN_DIR/zsh-git-ai.zsh" 2>/dev/null || true + source "$PLUGIN_DIR/zsh-git-ai.plugin.zsh" 2>/dev/null || true # Default should be anthropic assert_equals "$ZSH_GIT_AI_PROVIDER" "anthropic" teardown_test_env @@ -24,7 +24,7 @@ test_load_provider_success() { } # Source just the load_provider function - source "$PLUGIN_DIR/zsh-git-ai.zsh" 2>/dev/null || true + source "$PLUGIN_DIR/zsh-git-ai.plugin.zsh" 2>/dev/null || true local result load_provider "anthropic" >/dev/null 2>&1 result=$? @@ -38,7 +38,7 @@ test_load_provider_invalid() { export ZSH_GIT_AI_PROVIDER="invalid_provider" # Source just the load_provider function - source "$PLUGIN_DIR/zsh-git-ai.zsh" 2>/dev/null || true + source "$PLUGIN_DIR/zsh-git-ai.plugin.zsh" 2>/dev/null || true local output output=$(load_provider "invalid_provider" 2>&1) local result=$? @@ -50,7 +50,7 @@ test_load_provider_invalid() { test_spinner_function_exists() { setup_test_env - source "$PLUGIN_DIR/zsh-git-ai.zsh" 2>/dev/null || true + source "$PLUGIN_DIR/zsh-git-ai.plugin.zsh" 2>/dev/null || true # Check if show_spinner function is defined if type show_spinner >/dev/null 2>&1; then diff --git a/zsh-git-ai.zsh b/zsh-git-ai.plugin.zsh similarity index 76% rename from zsh-git-ai.zsh rename to zsh-git-ai.plugin.zsh index 0fe05e0..cade3d3 100644 --- a/zsh-git-ai.zsh +++ b/zsh-git-ai.plugin.zsh @@ -3,29 +3,7 @@ # Git Commit AI - Generate commit messages with AI providers # Get the directory where this script is located -# Try multiple methods to find the script directory -if [[ -n "${BASH_SOURCE[0]}" ]]; then - SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -elif [[ -n "${(%):-%x}" ]]; then - # ZSH-specific: %x expands to the name of the file being sourced - SCRIPT_DIR="${${(%):-%x}:A:h}" -elif [[ -n "$0" ]] && [[ "$0" != "zsh" ]] && [[ "$0" != "-zsh" ]] && [[ "$0" != "/bin/zsh" ]] && [[ "$0" != "/usr/bin/zsh" ]]; then - SCRIPT_DIR="${0:A:h}" -else - # Fallback: try to find the script in common locations - for dir in ~/Apps/zsh-git-ai ~/.oh-my-zsh/custom/plugins/zsh-git-ai /opt/homebrew/share/zsh-git-ai /usr/local/share/zsh-git-ai; do - if [[ -f "$dir/zsh-git-ai.zsh" ]]; then - SCRIPT_DIR="$dir" - break - fi - done -fi - -# Verify we found the script directory -if [[ -z "$SCRIPT_DIR" ]] || [[ ! -d "$SCRIPT_DIR/lib/providers" ]]; then - echo "Error: Could not determine script directory. Please check your installation." >&2 - return 1 -fi +local SCRIPT_DIR="${0:A:h}" # Default provider ZSH_GIT_AI_PROVIDER="${ZSH_GIT_AI_PROVIDER:-anthropic}" From b3efd24b78ea021187d384e6e00d347caa3b3ef2 Mon Sep 17 00:00:00 2001 From: Matheus Lima Date: Fri, 11 Jul 2025 14:33:34 -0300 Subject: [PATCH 3/4] Remove temporary zsh test script --- tmp/test.zsh | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tmp/test.zsh diff --git a/tmp/test.zsh b/tmp/test.zsh deleted file mode 100644 index d5c70b3..0000000 --- a/tmp/test.zsh +++ /dev/null @@ -1 +0,0 @@ -SCRIPT_DIR="${0:A:h}"; echo "Script dir: $SCRIPT_DIR" From 1f90d93f7dc747ca74fa8d42dcccea4e95c272cc Mon Sep 17 00:00:00 2001 From: Matheus Lima Date: Fri, 11 Jul 2025 14:38:33 -0300 Subject: [PATCH 4/4] Update plugin file path in workflow tests --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cc932f1..88ce710 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: - name: Test plugin loading run: | zsh -c " - source zsh-git-ai.zsh 2>/dev/null || true + source zsh-git-ai.plugin.zsh 2>/dev/null || true if [[ -z \"\$ZSH_GIT_AI_PROVIDER\" ]]; then echo 'ERROR: Plugin failed to load' exit 1 @@ -33,7 +33,7 @@ jobs: - name: Test provider validation run: | zsh -c " - source zsh-git-ai.zsh 2>/dev/null || true + source zsh-git-ai.plugin.zsh 2>/dev/null || true # Test anthropic provider validation export ZSH_GIT_AI_PROVIDER='anthropic' @@ -80,7 +80,7 @@ jobs: - name: Test load_provider function run: | zsh -c " - source zsh-git-ai.zsh 2>/dev/null || true + source zsh-git-ai.plugin.zsh 2>/dev/null || true # Test loading valid provider export ANTHROPIC_API_KEY='test-key'