use crate::compsys::ported::_requested::_requested;
use crate::compsys::ported::_tags::_tags;
use crate::ported::exec_hooks::dispatch_function_call;
use crate::ported::params::{getsparam, setsparam};
use crate::ported::zle::compcore::get_compstate_str;
pub fn _tilde(args: &[String]) -> i32 {
if !get_compstate_str("quote").unwrap_or_default().is_empty() {
return 1;
}
let mut ret: i32 = 1;
let suffix = getsparam("SUFFIX").unwrap_or_default();
let suf: Vec<String> = if suffix.contains('/') {
let head = suffix.splitn(2, '/').next().unwrap_or("").to_string();
let tail = suffix.splitn(2, '/').nth(1).unwrap_or("").to_string();
let isuf = getsparam("ISUFFIX").unwrap_or_default();
let _ = setsparam("ISUFFIX", &format!("/{}{}", tail, isuf));
let _ = setsparam("SUFFIX", &head);
vec!["-S".to_string(), "".to_string()]
} else {
vec!["-qS/".to_string()]
};
let _ = _tags(&[
"users".to_string(),
"named-directories".to_string(),
"directory-stack".to_string(),
]);
loop {
if _tags(&[]) != 0 {
break;
}
if _requested(&["users".to_string()]) == 0 {
let mut users_args: Vec<String> = suf.clone();
users_args.extend(args.iter().cloned());
if dispatch_function_call("_users", &users_args).unwrap_or(1) == 0 {
ret = 0;
}
}
let mut nd_args: Vec<String> = vec![
"named-directories".to_string(),
"expl".to_string(),
"named directory".to_string(),
"compadd".to_string(),
];
nd_args.extend(suf.iter().cloned());
nd_args.extend(args.iter().cloned());
nd_args.push("-k".to_string());
nd_args.push("nameddirs".to_string());
if _requested(&nd_args) == 0 {
ret = 0;
}
if _requested(&["directory-stack".to_string()]) == 0 {
if dispatch_function_call("_directory_stack", &suf).unwrap_or(1) == 0 {
ret = 0;
}
}
if ret == 0 {
return 0;
}
}
ret
}
#[cfg(test)]
mod tests {
use super::*;
use crate::ported::zle::compcore::set_compstate_str;
#[test]
fn quote_set_returns_one() {
let _g = crate::test_util::global_state_lock();
set_compstate_str("quote", "'");
assert_eq!(_tilde(&[]), 1);
set_compstate_str("quote", "");
}
}