Improved sudo handling in autocomplete

This commit is contained in:
Justine Pelletreau 2023-11-22 14:14:13 +01:00
parent 890197e12c
commit 56e5d4e63d

View File

@ -109,33 +109,36 @@ impl Search {
fn discriminate_search_type(input: &String) -> SearchType {
let tamere = input.clone();
let tamere2 = tamere.split("|")
.collect::<Vec<&str>>();
let mut command = String::from(*tamere2.last().unwrap());
//Special cases
//./Means we want to execute something in place
if input.starts_with("./") || input.starts_with(" ./") {
if command.starts_with("./") || command.starts_with(" ./") {
return SearchType::FileSearch;
}
if input.starts_with("sudo") || input.starts_with("watch ") {
if command.starts_with("watch ") {
return SearchType::CmdSearch;
}
let mut a = tamere.split(" ").collect::<Vec<&str>>();
//sudo is not taken into account when autocompleting
command = command.replace("sudo ", "");
let mut a = command.split(" ").collect::<Vec<&str>>();
let _y = String::from(a.pop().unwrap());
let mut x = String::from(a.join(" ").trim());
if x.len() > 0 {
x.push_str(" ")
};
if x.pop() == Some(' ') {
if x.pop() == Some('|') {
return SearchType::CmdSearch;
} else {
return SearchType::FileSearch;
}
let y = x.split(" ").collect::<Vec<&str>>();
if y.len() > 1 {
return SearchType::FileSearch;
} else {
return SearchType::CmdSearch;
}
}
}