Skip to content

Commit

Permalink
Add complete -a
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Dec 22, 2024
1 parent 8cb629b commit 0e9d401
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions .sushrc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ _colcon_comp () {
} && complete -F _colcon_comp colcon

complete -A stopped -P '"%' -S '"' bg
complete -a unalias
complete -c sudo xargs which
complete -j -P '"%' -S '"' disown fg jobs
complete -u groups w
Expand Down
17 changes: 15 additions & 2 deletions src/core/builtins/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub fn compgen(core: &mut ShellCore, args: &mut Vec<String>) -> i32 {
replace_args_compgen(&mut args);

let ans = match args[1].as_str() {
"-a" => compgen_a(core, &mut args),
"-c" => compgen_c(core, &mut args),
"-d" => compgen_d(core, &mut args),
"-f" => compgen_f(core, &mut args),
Expand Down Expand Up @@ -144,6 +145,19 @@ fn drop_unmatch(args: &mut Vec<String>, pos: usize, list: &mut Vec<String>) {
}
}

pub fn compgen_a(core: &mut ShellCore, args: &mut Vec<String>) -> Vec<String> {
let mut commands = vec![];

let mut aliases: Vec<String> = core.db.aliases.clone().into_keys().collect();
commands.append(&mut aliases);

let head = get_head(args, 2);
if head != "" {
commands.retain(|a| a.starts_with(&head));
}
commands
}

pub fn compgen_c(core: &mut ShellCore, args: &mut Vec<String>) -> Vec<String> {
let mut commands = vec![];
if args.len() > 2 {
Expand Down Expand Up @@ -214,8 +228,6 @@ pub fn compgen_v(core: &mut ShellCore, args: &mut Vec<String>) -> Vec<String> {
if head != "" {
commands.retain(|a| a.starts_with(&head));
}
let mut command_in_paths = command_list(&head, core);
commands.append(&mut command_in_paths);
commands
}

Expand Down Expand Up @@ -284,6 +296,7 @@ pub fn compgen_j(core: &mut ShellCore, args: &mut Vec<String>) -> Vec<String> {

fn opt_to_action(arg: &str) -> String {
match arg {
"-a" => "alias",
"-c" => "command",
"-j" => "job",
"-u" => "user",
Expand Down
1 change: 1 addition & 0 deletions src/feeder/terminal/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ impl Terminal {
if core.completion_actions.contains_key(com) {
let (action, options) = core.completion_actions[com].clone();
let mut cands = match action.as_ref() {
"alias" => completion::compgen_a(core, args),
"command" => completion::compgen_c(core, args),
"job" => completion::compgen_j(core, args),
"stopped" => completion::compgen_stopped(core, args),
Expand Down

0 comments on commit 0e9d401

Please sign in to comment.