Skip to content

Commit

Permalink
Support complete -v
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Dec 22, 2024
1 parent 061538c commit e83d24f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
5 changes: 3 additions & 2 deletions .sushrc
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ _colcon_comp () {
fi
} && complete -F _colcon_comp colcon

complete -u groups w
complete -A stopped -P '"%' -S '"' bg
complete -c sudo xargs which
complete -j -P '"%' -S '"' disown fg jobs
complete -A stopped -P '"%' -S '"' bg
complete -u groups w
complete -v unset

command_not_found_handle() {
if [ -e /usr/lib/command-not-found ] ; then
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sush"
version = "0.9.9"
version = "0.9.10"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
36 changes: 21 additions & 15 deletions src/core/builtins/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub fn compgen(core: &mut ShellCore, args: &mut Vec<String>) -> i32 {
"-h" => compgen_h(core, &mut args), //history (sush original)
"-j" => compgen_j(core, &mut args),
"-u" => compgen_u(core, &mut args),
"-v" => compgen_v(core, &mut args),
"-A stopped" => compgen_stopped(core, &mut args),
"-W" => {
if args.len() < 2 {
Expand Down Expand Up @@ -199,6 +200,25 @@ pub fn compgen_h(core: &mut ShellCore, _: &mut Vec<String>) -> Vec<String> {
ans
}

pub fn compgen_v(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 mut functions: Vec<String> = core.db.functions.clone().into_keys().collect();
commands.append(&mut functions);
let mut vars: Vec<String> = core.db.get_keys();
commands.append(&mut vars);

let head = get_head(args, 2);
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
}

fn compgen_large_w(core: &mut ShellCore, args: &mut Vec<String>) -> Vec<String> {
let mut ans: Vec<String> = vec![];
let mut feeder = Feeder::new(&args[2]);
Expand Down Expand Up @@ -267,6 +287,7 @@ fn opt_to_action(arg: &str) -> String {
"-c" => "command",
"-j" => "job",
"-u" => "user",
"-v" => "variable",
_ => "",
}.to_string()
}
Expand Down Expand Up @@ -296,21 +317,6 @@ pub fn complete(core: &mut ShellCore, args: &mut Vec<String>) -> i32 {
return 0;
}

/*
if args[1] == "-u" {
for command in &args[2..] {
core.completion_actions.insert(command.clone(), ("user".to_string(), options.clone()));
}
return 0;
}
if args[1] == "-j" {
for command in &args[2..] {
core.completion_actions.insert(command.clone(), ("job".to_string(), options.clone()));
}
return 0;
}*/

if args.len() > 3 && args[1] == "-F" {
core.completion_functions.insert(args[3].clone(), args[2].clone());
return 0;
Expand Down
5 changes: 3 additions & 2 deletions src/feeder/terminal/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ impl Terminal {
let (action, options) = core.completion_actions[com].clone();
let mut cands = match action.as_ref() {
"command" => completion::compgen_c(core, args),
"user" => completion::compgen_u(core, args),
"stopped" => completion::compgen_stopped(core, args),
"job" => completion::compgen_j(core, args),
"stopped" => completion::compgen_stopped(core, args),
"user" => completion::compgen_u(core, args),
"variable" => completion::compgen_v(core, args),
_ => vec![],
};

Expand Down

0 comments on commit e83d24f

Please sign in to comment.