completers
[!WARNING] This crate is still a prototype, and is subject to BREAKING changes without notice.
A tiny Rust-native shell completion solution.
💡 Examples
See examples for a few examples of how to use this crate.
📖 Usage
Rust Part
Candidates
First, define a completion handler function that takes a [Completion] struct as an argument and returns a vector of completion candidates:
use Completion;
Then, call [handle_completion] BEFORE any other command that writes to stdout in your main function:
use ;
#
#
Delegate
To delegate completion, we should first match against [Completion::init()]:
use ;
use exit;
#
#
Then, construct or mutate the [Completion] object in the delegate function. We'll delegate to cargo build --example for example:
# use ;
# use exit;
#
/// Delegates completion to `cargo build --example`, exit if successful.
Shell Part
Bash
[!NOTE] By using
completers, we assume that you've gotbash-completioninstalled. Some features such as completion delegate won't work without it.
Generate and evaluate the shell code via:
You should be able to complete your commands now. To enable completion across all your terminal sessions, you can add the above code to your completions directory, like:
You can also use /usr/share/bash-completion/completions/ as the directory, if you want the completion to be available system-wise.
Nushell
Instructions for lazy loading completions will be updated once nushell/nushell#4874 is resolved. For now, you'll have to:
COMPLETE=nu my_binary o> somewhere/handy.nu
And then source the file from your ($nu.default-config-dir)/config.nu:
source somewhere/handy.nu
Note that completions will only work for my_binary, and not ./my_binary or /path/to/my_binary.
The completers Binary
Currently, the completers binary does nothing.
⚙️ Details
See CAVEATS.md for a list of known problems, and see MECHANISM.md for a detailed explanation of how this works, in case you're curious.
🎉 Credits
clap, whose code and API is used as a reference. Whenclap's Rust-Native Completion Engine is stablized, this crate will be deprecated in favor of it.complete-alias, whose shell code helped a lot.
✅ TODO
- Escape special characters in generated shell code & completion candidates
- Completion delegation
- Need to consider how to design the API
- Prototypes available in
prototype
- Extensibility (API?)