use crate::compsys::ported::shared::dispatch_action_command;
use crate::ported::params::getsparam;
pub fn _bash_completions() -> i32 {
let _fn_scope = crate::compsys::ported::shared::FnScope::enter("_bash_completions");
let keys = getsparam("KEYS").unwrap_or_default();
let key = keys.chars().last().unwrap_or(' ');
let line: u64 = match key {
'!' => 33,
'$' => 35,
'@' => 38,
'/' => 40,
'~' => 42,
_ => 44,
};
let argv: Vec<String> = match key {
'!' => vec!["_command_names".to_string()],
'$' => vec![
"-".to_string(),
"parameters".to_string(),
"_wanted".to_string(),
"parameters".to_string(),
"expl".to_string(),
"exported parameter".to_string(),
"_parameters".to_string(),
"-g".to_string(),
"*export*".to_string(),
],
'@' => vec!["_hosts".to_string()],
'/' => vec!["_files".to_string()],
'~' => vec!["_users".to_string()],
_ => {
return dispatch_action_command(
"_message",
&[format!("Key {} is not understood", key)],
line,
)
}
};
dispatch_action_command("_main_complete", &argv, line)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::ported::params::setsparam;
#[test]
fn unknown_key_returns_one() {
let _g = crate::test_util::global_state_lock();
let _ = setsparam("KEYS", "abc");
assert_eq!(_bash_completions(), 1);
}
#[test]
fn returns_one_without_executor() {
let _g = crate::test_util::global_state_lock();
let _ = setsparam("KEYS", "\\e!");
assert_eq!(_bash_completions(), 1);
}
}