shellcomp
shellcomp is a deployment layer for shell completions in Rust CLI projects.
It does not generate completion scripts. It installs, wires, detects, and removes them in a way that is predictable, idempotent, and structured for callers.
What It Handles
- Default install paths for Bash, Zsh, Fish, PowerShell, and Elvish
write-if-changedcompletion file writes- Managed
~/.bashrcfallback wiring when Bash has no system loader - Managed
~/.zshrcwiring forfpathandcompinit - Native Fish completion directory installs
- Managed PowerShell profile wiring
- Managed Elvish
rc.elvwiring - Symmetric uninstall cleanup
- Legacy managed-block migration helpers
- Structured reports that callers can render however they want
Supported Shells
- Bash
- Zsh
- Fish
- PowerShell
- Elvish
Shell::Other(_) remains the explicit unsupported-shell escape hatch.
Add The Dependency
Until the crate is published, depend on a local checkout or a git revision:
[]
= { = "../shellcomp-rs" }
Once published, replace the path dependency with a version:
[]
= "0.1.0"
Enable clap integration if you want the library to render completions from clap::CommandFactory
directly:
[]
= { = "0.1.0", = ["clap"] }
= { = "4.6.0", = ["derive"] }
Install A Prebuilt Completion Script
use ;
Integrate With clap
use Parser;
use ;
The examples above install into managed shell locations. Use path_override during local testing if
you do not want to touch your real shell profile yet.
Uninstall
use ;
Custom Paths
When path_override is set, install keeps the legacy behavior for non-default custom paths and
reports ActivationMode::Manual. If the override is exactly the shell's managed default path, the
default activation semantics still apply. If you want a custom path plus managed Bash/Zsh/PowerShell/Elvish
activation, use install_with_policy(..., ActivationPolicy::AutoManaged).
use PathBuf;
use ;
Legacy Block Migration
If your CLI previously shipped its own managed markers, rewrite them into shellcomp markers
before or during migration:
use ;
Examples
cargo run --example install_prebuiltcargo run --example roundtrip_custom_pathcargo run --example inspect_managed_pathscargo run --example clap_integration --features clap