use crate::ported::exec_hooks::dispatch_function_call;
use crate::ported::params::getsparam;
pub fn _bash_completions() -> i32 {
let keys = getsparam("KEYS").unwrap_or_default();
let key = keys.chars().last().unwrap_or(' ');
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 1,
};
dispatch_function_call("_main_complete", &argv).unwrap_or(1)
}
#[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);
}
}