MCPcopy Index your code
hub / github.com/JoshMcguigan/shell_completion

github.com/JoshMcguigan/shell_completion @v0.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.0 ↗ · + Follow
67 symbols 151 edges 4 files 9 documented · 13%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

shell_completion Build Status crates.io badge

Shell completions, which provide auto-complete for CLI applications, are typically written in Bash. This crate provides low level primitives for writing shell completion scripts in Rust.

Usage

Shell completion scripts are written as normal Rust binaries. A minimal example is below:

use shell_completion::{BashCompletionInput, CompletionInput, CompletionSet};

fn main() {
    let input = BashCompletionInput::from_env()
        .expect("Missing expected environment variables");

    let completions = input.complete_subcommand(vec!["add", "commit"]);

    completions.suggest();
}

A more advanced example is available in the cargo_completion crate within this workspace. To try it out, run cargo install --force --path cargo_completion/ && complete -C _cargo_completion cargo, then type cargo run --<TAB> in the same shell.

The complete command registered our shell completion script for cargo. Note that complete commands do not persist (they are only active in the shell where you run complete), so if you want to use a completion long term you'll want to add the complete command to your ~/.bash_profile.

See this blog post for more details.

Users

This crate is not quite ready for production use, but if you are an early adopter, feel free to make a PR adding yourself to the list below.

  • N/A

License

Licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

Contribution

All forms of contribution are valued. I've created issues for many high level topics of exploration, and any feedback there will be very helpful in moving this crate in the right direction. Of course, code contributions are appreciated as well.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Extension points exported contracts — how you extend this code

CompletionInput (Interface)
(no doc) [1 implementers]
shell_completion/src/lib.rs
CompletionSet (Interface)
(no doc) [1 implementers]
shell_completion/src/lib.rs

Core symbols most depended-on inside this repo

complete
called by 11
cargo_completion/src/main.rs
assert_split
called by 11
shell_completion/src/split.rs
push_character
called by 10
shell_completion/src/split.rs
complete_subcommand
called by 9
shell_completion/src/lib.rs
previous_word
called by 8
shell_completion/src/lib.rs
complete_directory
called by 4
shell_completion/src/lib.rs
args
called by 3
shell_completion/src/bash.rs
arg_index
called by 3
shell_completion/src/bash.rs

Shape

Function 36
Method 22
Class 4
Enum 3
Interface 2

Languages

Rust100%

Modules by API surface

shell_completion/src/split.rs27 symbols
cargo_completion/src/main.rs16 symbols
shell_completion/src/lib.rs14 symbols
shell_completion/src/bash.rs10 symbols

For agents

$ claude mcp add shell_completion \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact