Skip to content

Commit

Permalink
Add aliases, funcs, builtins to default cmd completion (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
reubeno authored Jun 10, 2024
1 parent 156e760 commit e6d319a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
33 changes: 33 additions & 0 deletions brush-core/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ fn get_command_completions(shell: &Shell, context: &CompletionContext) -> Vec<St
let mut candidates = HashSet::new();
let glob_pattern = std::format!("{}*", context.token_to_complete);

// Look for external commands.
for path in shell.find_executables_in_path(&glob_pattern) {
if let Some(file_name) = path.file_name() {
candidates.insert(file_name.to_string_lossy().to_string());
Expand All @@ -908,8 +909,40 @@ fn get_completions_using_basic_lookup(
.token_to_complete
.contains(std::path::MAIN_SEPARATOR)
{
// Add external commands.
let mut command_completions = get_command_completions(shell, context);
candidates.append(&mut command_completions);

// Add built-in commands.
for (name, registration) in &shell.builtins {
if !registration.disabled && name.starts_with(context.token_to_complete) {
candidates.push(name.to_owned());
}
}

// Add shell functions.
for (name, _) in shell.funcs.iter() {
if name.starts_with(context.token_to_complete) {
candidates.push(name.to_owned());
}
}

// Add aliases.
for name in shell.aliases.keys() {
if name.starts_with(context.token_to_complete) {
candidates.push(name.to_owned());
}
}

// Add keywords.
for keyword in shell.get_keywords() {
if keyword.starts_with(context.token_to_complete) {
candidates.push(keyword.clone());
}
}

// Sort.
candidates.sort();
}

#[cfg(windows)]
Expand Down
1 change: 0 additions & 1 deletion brush-parser/src/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ peg::parser! {
rule tilde_prefix() -> WordPiece =
tilde_parsing_enabled() "~" cs:$((!"/" [c])*) { WordPiece::TildePrefix(cs.to_owned()) }

// TODO: Constrain syntax of parameter in brace-less form
// TODO: Deal with fact that there may be a quoted word or escaped closing brace chars.
// TODO: Improve on how we handle a '$' not followed by a valid variable name or parameter.
rule parameter_expansion() -> WordPiece =
Expand Down

0 comments on commit e6d319a

Please sign in to comment.