diff --git a/src/shell/autocomplete.rs b/src/shell/autocomplete.rs index 71cc594..731e3b6 100644 --- a/src/shell/autocomplete.rs +++ b/src/shell/autocomplete.rs @@ -109,33 +109,36 @@ impl Search { fn discriminate_search_type(input: &String) -> SearchType { let tamere = input.clone(); + let tamere2 = tamere.split("|") + .collect::>(); + 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::>(); + //sudo is not taken into account when autocompleting + command = command.replace("sudo ", ""); + + let mut a = command.split(" ").collect::>(); 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::>(); + if y.len() > 1 { + return SearchType::FileSearch; } else { return SearchType::CmdSearch; } + } }