Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- `cx completion <shell>` generates shell completion scripts for bash, zsh, fish, powershell, and elvish.

## [0.7.1] - 2026-05-15

### Added
Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ rayon = "1"
redb = "3"
bincode = "1"
dirs = "6.0.0"
clap_complete = "4.6.5"

[dev-dependencies]
tempfile = "3"
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,26 @@ Use `--offset N` to page forward, `--all` to bypass the limit, or `--limit N` to

With `--json`, paginated output uses `{total, offset, limit, results: [...]}`. Non-paginated output remains a bare array.

## Shell completion

`cx completion <shell>` prints a completion script to stdout. Supported shells: `bash`, `zsh`, `fish`, `powershell`, `elvish`.

```bash
# Bash — current shell
source <(cx completion bash)
# Bash — persist (Linux)
cx completion bash | sudo tee /etc/bash_completion.d/cx > /dev/null

# Zsh — add to a directory on your $fpath, e.g.
cx completion zsh > "${fpath[1]}/_cx"

# Fish
cx completion fish > ~/.config/fish/completions/cx.fish

# PowerShell — add to your profile
cx completion powershell | Out-String | Invoke-Expression
```

## How it works

On first invocation, cx builds an index by parsing all source files with tree-sitter. The index stores symbols, signatures, and byte ranges for every file; overview derives line ranges from those byte ranges. Subsequent invocations incrementally update only changed files.
Expand Down
13 changes: 12 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod query;
mod language;
mod util;

use clap::{Parser, Subcommand};
use clap::{CommandFactory, Parser, Subcommand};
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -105,6 +105,11 @@ enum Commands {
},
/// Print the agent skill file to stdout
Skill,
/// Generate a shell completion script
Completion {
/// Shell to generate completions for
shell: clap_complete::Shell,
},
/// Manage the index cache
Cache {
#[command(subcommand)]
Expand Down Expand Up @@ -218,6 +223,12 @@ fn main() {
print!("{}", include_str!("skill.md"));
0
}
Commands::Completion { shell } => {
let mut cmd = Cli::command();
let bin_name = cmd.get_name().to_string();
clap_complete::generate(shell, &mut cmd, bin_name, &mut std::io::stdout());
0
}
Commands::Cache { action } => {
let root = resolve_root(&cli.root, None);
let path = index::cache_path_for(&root);
Expand Down
24 changes: 24 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,3 +926,27 @@ fn explicit_root_overrides_path_hint() {
// Should fail because B's path isn't under A's root
assert!(!out.status.success(), "--root should override path-based discovery");
}

#[test]
fn completion_emits_script_for_each_shell() {
// Each shell should produce a non-empty script and exit successfully.
// Spot-check a shell-specific marker so we know the right generator ran.
let cases = [
("bash", "_cx()"),
("zsh", "#compdef cx"),
("fish", "complete -c cx"),
("powershell", "Register-ArgumentCompleter"),
];
for (shell, marker) in cases {
let out = cx().args(["completion", shell]).output().unwrap();
assert!(out.status.success(), "completion {shell} should succeed: {}", String::from_utf8_lossy(&out.stderr));
let stdout = String::from_utf8_lossy(&out.stdout);
assert!(stdout.contains(marker), "completion {shell} missing marker {marker:?}: {stdout}");
}
}

#[test]
fn completion_rejects_unknown_shell() {
let out = cx().args(["completion", "notashell"]).output().unwrap();
assert!(!out.status.success(), "unknown shell should fail");
}
Loading