Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Integration Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
integration-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Run integration tests
run: ./test_integration.sh
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ llm install llm-cmd-comp
```
Then install the shell integration for your preferred shell.

- **Fish**: place `share/llm-cmd-comp.fish` in `~/.config/fish/conf.d/`.
- **Zsh**: source `share/llm-cmd-comp.zsh` in your `~/.zshrc`.
- **Bash**: source `share/llm-cmd-comp.bash` in your `~/.bashrc`.
- **Fish**: add `llm cmdcomp --init fish | source` in a file in `~/.config/fish/conf.d/`.
- **Zsh**: add `eval "$(llm cmdcomp --init zsh)"` to your `~/.zshrc`.
- **Bash**: add `eval "$(llm cmdcomp --init bash)"` to your `~/.bashrc`.

## Usage

Expand All @@ -38,7 +38,7 @@ Neat ways you can use this feature:
To set up this plugin locally, first checkout the code. Then create a new virtual environment:

```bash
cd llm-cmd
cd llm-cmd-comp
python3 -m venv venv
source venv/bin/activate
```
Expand Down
23 changes: 21 additions & 2 deletions llm_cmd_comp.py → llm_cmd_comp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,33 @@
@llm.hookimpl
def register_commands(cli):
@cli.command()
@click.option(
"--init",
type=click.Choice(["bash", "zsh", "fish"]),
help="Output shell integration code for the specified shell and exit.",
)
@click.argument("args", nargs=-1)
@click.option("-m", "--model", default=None, help="Specify the model to use")
@click.option("-s", "--system", help="Custom system prompt")
@click.option("--key", help="API key to use")
def cmdcomp(args, model, system, key):
"""Generate commands directly in your command line (requires shell integration)"""
def cmdcomp(init, args, model, system, key):
"""Generate commands directly in your command line (requires shell integration)
Optionally output shell integration code with --init SHELL (bash, zsh, fish)
"""
import sys
from llm.cli import get_default_model

if init:
share_dir = os.path.join(os.path.dirname(__file__), "share")
filename = f"llm-cmd-comp.{init}"
filepath = os.path.join(share_dir, filename)
if not os.path.exists(filepath):
click.echo(f"Error: Integration file for {init} not found.", err=True)
sys.exit(1)
with open(filepath) as f:
click.echo(f.read())
return

prompt = " ".join(args)
model_id = model or get_default_model()
model_obj = llm.get_model(model_id)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ version = "1.1.1"
description = "Use LLM to generate commands for your shell"
readme = "README.md"
authors = [{name = "Ryan Patterson"}]
license = {text = "Apache-2.0"}
classifiers = [
"License :: OSI Approved :: Apache Software License"
]
license = "Apache-2.0"
license-files = ["LICENSE"]
dependencies = [
"llm",
"prompt_toolkit>=3.0.43",
Expand All @@ -20,3 +18,9 @@ Issues = "https://github.com/CGamesPlay/llm-cmd-comp/issues"

[project.entry-points.llm]
cmdcomp = "llm_cmd_comp"

[tool.setuptools]
include-package-data = true

[tool.setuptools.package-data]
llm_cmd_comp = ["share/*"]
32 changes: 32 additions & 0 deletions test_integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Integration test for llm-cmd-comp package
# This test:
# 1. Builds the package to a wheel
# 2. Installs the wheel in a clean virtual environment
# 3. Tests that `llm cmdcomp --init bash` works correctly

set -eux

TEMP_DIR=$(mktemp -d)
cleanup() {
rm -rf "$TEMP_DIR"
}
trap cleanup EXIT

rm -rf dist
python -m pip install build
python -m build --wheel

# Locate the wheel file
WHEEL_FILE=$(find dist -name "*.whl" | head -1)
[[ -n "$WHEEL_FILE" ]]

# Set up a venv
VENV_PATH="$TEMP_DIR/test_venv"
python -m venv "$VENV_PATH"
source "$VENV_PATH/bin/activate"
pip install llm
llm install "$WHEEL_FILE"

llm cmdcomp --init bash