pub struct GenerateCompletionArgs {
pub shell: Shell,
}Expand description
Command-line arguments for generating shell completion scripts.
The generate-completion command creates shell-specific completion scripts that enable intelligent tab completion for SubX commands and arguments. This greatly enhances the command-line user experience by providing context-aware suggestions and reducing typing requirements.
§Completion Capabilities
Generated scripts provide completion for:
- Subcommands:
match,convert,sync,detect-encoding, etc. - Flags and Options:
--format,--output,--confidence, etc. - Enum Values: Available formats, AI providers, sync methods
- File Paths: Intelligent file and directory completion
- Configuration Keys: Valid configuration setting names
§Shell Integration
Each shell has different integration methods:
- Immediate: Load completion in current session
- Persistent: Add to shell configuration for permanent availability
- System-wide: Install for all users on the system
- Per-project: Enable completion in specific project directories
§Performance Considerations
Completion scripts are optimized for performance:
- Lazy Loading: Completions are generated on-demand
- Caching: Results are cached where appropriate
- Minimal Overhead: Scripts add minimal startup time to shell
- Incremental Updates: Only regenerate when command structure changes
§Examples
use subx_cli::cli::GenerateCompletionArgs;
use clap_complete::Shell;
// Generate Bash completion
let bash_args = GenerateCompletionArgs {
shell: Shell::Bash,
};
// Generate Zsh completion
let zsh_args = GenerateCompletionArgs {
shell: Shell::Zsh,
};
// Generate Fish completion
let fish_args = GenerateCompletionArgs {
shell: Shell::Fish,
};Fields§
§shell: ShellTarget shell for completion script generation.
Specifies which shell environment the completion script should target. Each shell has different syntax and capabilities, so the generated script is optimized for the specific shell’s completion system.
§Shell-Specific Features
§Bash
- Traditional completion with
completecommand - Basic argument and flag completion
- Compatible with most Linux distributions
- Works with Bash 4.0+ (recommended: 4.4+)
§Zsh
- Advanced completion with
_argumentsfunction - Rich help text and description display
- Smart caching and performance optimization
- Compatible with Oh My Zsh and other frameworks
§Fish
- Native completion with
completecommand - Excellent help text integration
- Real-time completion suggestions
- Works with all Fish versions 3.0+
§PowerShell
- Register-ArgumentCompleter integration
- Full .NET completion capabilities
- Works on Windows, Linux, and macOS
- Compatible with PowerShell 5.1+ and PowerShell Core
§Elvish
- Modern completion with structured data
- Rich metadata and help integration
- Advanced completion customization
- Works with Elvish 0.18+
§Installation Instructions
§Bash
# Temporary (current session only)
eval "$(subx generate-completion bash)"
# Permanent (add to ~/.bashrc)
echo 'eval "$(subx generate-completion bash)"' >> ~/.bashrc
# System-wide (requires sudo)
subx generate-completion bash > /etc/bash_completion.d/subx§Zsh
# Temporary (current session only)
eval "$(subx generate-completion zsh)"
# Permanent (add to ~/.zshrc)
echo 'eval "$(subx generate-completion zsh)"' >> ~/.zshrc
# Oh My Zsh (create plugin)
mkdir -p ~/.oh-my-zsh/custom/plugins/subx
subx generate-completion zsh > ~/.oh-my-zsh/custom/plugins/subx/_subx§Fish
# Save to Fish completions directory
subx generate-completion fish > ~/.config/fish/completions/subx.fish
# System-wide installation
sudo subx generate-completion fish > /usr/share/fish/completions/subx.fish§PowerShell
# Add to PowerShell profile
subx generate-completion powershell | Out-String | Invoke-Expression
# Permanent installation (add to profile)
Add-Content $PROFILE "subx generate-completion powershell | Out-String | Invoke-Expression"§Troubleshooting
Common issues and solutions:
- Completion not working: Verify shell version compatibility
- Slow completion: Check for conflicting completion scripts
- Missing commands: Ensure SubX is in PATH
- Permission errors: Use appropriate installation method for your system
§Examples
# Generate and view Bash completion
subx generate-completion bash
# Generate and install Fish completion
subx generate-completion fish > ~/.config/fish/completions/subx.fish
# Generate PowerShell completion and execute immediately
subx generate-completion powershell | Out-String | Invoke-ExpressionTrait Implementations§
Source§impl Args for GenerateCompletionArgs
impl Args for GenerateCompletionArgs
Source§fn augment_args<'b>(__clap_app: Command) -> Command
fn augment_args<'b>(__clap_app: Command) -> Command
Source§fn augment_args_for_update<'b>(__clap_app: Command) -> Command
fn augment_args_for_update<'b>(__clap_app: Command) -> Command
Append to
Command so it can instantiate self via
FromArgMatches::update_from_arg_matches_mut Read moreSource§impl Debug for GenerateCompletionArgs
impl Debug for GenerateCompletionArgs
Source§impl FromArgMatches for GenerateCompletionArgs
impl FromArgMatches for GenerateCompletionArgs
Source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
Source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches,
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>
Source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>
Assign values from
ArgMatches to self.Source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>
Assign values from
ArgMatches to self.Auto Trait Implementations§
impl Freeze for GenerateCompletionArgs
impl RefUnwindSafe for GenerateCompletionArgs
impl Send for GenerateCompletionArgs
impl Sync for GenerateCompletionArgs
impl Unpin for GenerateCompletionArgs
impl UnwindSafe for GenerateCompletionArgs
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.