Skip to content
/ sly Public

Shell AI command generator - converts natural language to shell commands using multiple AI providers

License

Notifications You must be signed in to change notification settings

sammyjoyce/sly

Repository files navigation

sly

Shell AI command generator - convert natural language to shell commands using AI.

Features

  • Multiple AI providers: Anthropic (Claude), Google (Gemini), OpenAI (GPT), Ollama (local models)
  • Shell integration: zsh with "# request" + Enter UX; bash with Ctrl-x a keybinding (optional Enter auto-expand with SLY_BASH_ENTER=1)
  • Context-aware: Detects project type, git status, current directory
  • Fast: Written in Zig 0.15.2+ with libcurl for minimal latency
  • Offline mode: Echo provider for testing without API keys

Installation

Prerequisites

  • Zig 0.15.2 or later
  • libcurl development headers:
    • Ubuntu/Debian: sudo apt-get install libcurl4-openssl-dev
    • macOS: brew install curl (or use system libcurl)
    • Arch: sudo pacman -S curl

Build from source

git clone https://codeberg.org/sam/sly.git
cd sly/
zig build -Doptimize=ReleaseSafe

Binary will be at zig-out/bin/sly.

Add to PATH

export PATH="$PWD/zig-out/bin:$PATH"

Add to ~/.bashrc or ~/.zshrc to persist.

Nix flake

  • Development shell: nix develop
  • Build the CLI: nix build or nix build .#sly (binary at ./result/bin/sly)
  • Run directly: nix run . -- "list all pdf files" (or nix run .#sly -- "list all pdf files")

First build will error with a vendor hash for Zig dependencies. Copy the suggested sha256-... into flake.nix where pkgs.lib.fakeHash is used, then rebuild.

Using on NixOS, you can either add the package to your environment.systemPackages, or import the included module and set defaults/env vars:

{
  inputs.sly.url = "path:/path/to/this/checkout"; # or your git remote

  outputs = { self, nixpkgs, sly, ... }: {
    nixosConfigurations.your-host = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        sly.nixosModules.default
        ({ config, pkgs, ... }: {
          programs.sly.enable = true;
          # Optional: set defaults or API keys (beware: Nix store visibility)
          programs.sly.provider = "anthropic";
          # programs.sly.anthropicApiKey = "..."; # prefer sops-nix/agenix instead
        })
      ];
    };
  };
}

Note: Do not commit API keys directly in Nix configs. Use sops-nix, agenix, or other secret management to keep credentials out of the Nix store.

Configuration

Set environment variables to configure providers and models:

# Choose provider (default: anthropic)
export SLY_PROVIDER=anthropic  # or gemini, openai, ollama, echo

# Anthropic (Claude)
export ANTHROPIC_API_KEY="sk-ant-..."
export SLY_ANTHROPIC_MODEL="claude-3-5-sonnet-20241022"  # default

# Google Gemini
export GEMINI_API_KEY="..."
export SLY_GEMINI_MODEL="gemini-2.0-flash-exp"  # default

# OpenAI (Responses API)
export OPENAI_API_KEY="sk-..."
export SLY_OPENAI_MODEL="gpt-4o"  # default
export SLY_OPENAI_URL="https://api.openai.com/v1/responses"  # default

# Ollama (local)
export SLY_OLLAMA_MODEL="llama3.2"  # default
export SLY_OLLAMA_URL="http://localhost:11434"  # default

# Custom system prompt extension
export SLY_PROMPT_EXTEND="Always use verbose flags"

Usage

CLI

# Direct invocation
sly "list all pdf files"
# Output: find . -name '*.pdf'

sly "show disk usage sorted by size"
# Output: du -sh * | sort -h

zsh integration

Add to ~/.zshrc:

source /path/to/sly/lib/sly.plugin.zsh

Then type:

# list all pdf files
# <press Enter>
# → Buffer becomes: find . -name '*.pdf'

Spinner animation shows progress. Press Enter again to execute, or edit first.

bash integration

Add to ~/.bashrc:

source /path/to/sly/lib/bash-sly.plugin.sh

Then type:

# list all pdf files
<press Ctrl-x a>
# → Buffer becomes: find . -name '*.pdf'

Press Enter to execute, or edit first.

Optional: enable Enter to auto-expand # lines (two-step UX) by adding:

export SLY_BASH_ENTER=1

With this set, on a line starting with # :

  • First Enter expands to the generated command (does not execute)
  • Second Enter executes the command

Development

Run tests

zig build test

Format code

zig fmt src/ build.zig

Test with echo provider (offline)

SLY_PROVIDER=echo sly "test query"
# Output: echo 'test query'

Environment Variables Reference

Variable Default Description
SLY_PROVIDER anthropic AI provider: anthropic, gemini, openai, ollama, echo
ANTHROPIC_API_KEY - Anthropic API key (required for anthropic provider)
SLY_ANTHROPIC_MODEL claude-3-5-sonnet-20241022 Anthropic model name
GEMINI_API_KEY - Google Gemini API key (required for gemini provider)
SLY_GEMINI_MODEL gemini-2.0-flash-exp Gemini model name
OPENAI_API_KEY - OpenAI API key (required for openai provider)
SLY_OPENAI_MODEL gpt-4o OpenAI model name
SLY_OPENAI_URL https://api.openai.com/v1/responses OpenAI API endpoint
SLY_OLLAMA_MODEL llama3.2 Ollama model name
SLY_OLLAMA_URL http://localhost:11434 Ollama server URL
SLY_PROMPT_EXTEND - Additional system prompt instructions

License

MIT - see LICENSE file

Contributing

Patches welcome! Send to the mailing list or open an issue on Codeberg.

About

Shell AI command generator - converts natural language to shell commands using multiple AI providers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •