diff --git a/.sushrc b/.sushrc index ff3540c9..72f15c36 100644 --- a/.sushrc +++ b/.sushrc @@ -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 diff --git a/src/core/builtins/completion.rs b/src/core/builtins/completion.rs index 5827c5e5..754ee3a5 100644 --- a/src/core/builtins/completion.rs +++ b/src/core/builtins/completion.rs @@ -102,6 +102,7 @@ pub fn compgen(core: &mut ShellCore, args: &mut Vec) -> 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), @@ -144,6 +145,19 @@ fn drop_unmatch(args: &mut Vec, pos: usize, list: &mut Vec) { } } +pub fn compgen_a(core: &mut ShellCore, args: &mut Vec) -> Vec { + let mut commands = vec![]; + + let mut aliases: Vec = 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) -> Vec { let mut commands = vec![]; if args.len() > 2 { @@ -214,8 +228,6 @@ pub fn compgen_v(core: &mut ShellCore, args: &mut Vec) -> Vec { 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 } @@ -284,6 +296,7 @@ pub fn compgen_j(core: &mut ShellCore, args: &mut Vec) -> Vec { fn opt_to_action(arg: &str) -> String { match arg { + "-a" => "alias", "-c" => "command", "-j" => "job", "-u" => "user", diff --git a/src/feeder/terminal/completion.rs b/src/feeder/terminal/completion.rs index 987e7e97..d84cb6ae 100644 --- a/src/feeder/terminal/completion.rs +++ b/src/feeder/terminal/completion.rs @@ -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),