chore: cleanup

This commit is contained in:
iff 2025-01-06 16:27:11 +01:00
parent 3460d66aac
commit ecdcee5969
4 changed files with 22 additions and 8 deletions

View file

@ -175,7 +175,12 @@ pub fn typo(suggest: &mut String, split_command: &[String], executables: &[Strin
} }
} }
pub fn exes(suggest: &mut String, split_command: &[String], executables: &[String], exes_list: &mut Vec<String>) { pub fn exes(
suggest: &mut String,
split_command: &[String],
executables: &[String],
exes_list: &mut Vec<String>,
) {
if suggest.contains("{{exes") { if suggest.contains("{{exes") {
let (placeholder, args) = eval_placeholder(suggest, "{{exes", "}}"); let (placeholder, args) = eval_placeholder(suggest, "{{exes", "}}");

View file

@ -83,7 +83,8 @@ pub fn runtime_match(
if pure_suggest.contains("{{command}}") { if pure_suggest.contains("{{command}}") {
pure_suggest = pure_suggest.replace("{{command}}", last_command); pure_suggest = pure_suggest.replace("{{command}}", last_command);
} }
let suggests = eval_suggest(&pure_suggest, last_command, error_msg, executables, shell); let suggests =
eval_suggest(&pure_suggest, last_command, error_msg, executables, shell);
for suggest in suggests { for suggest in suggests {
print!("{}", suggest); print!("{}", suggest);
print!("<_PR_BR>"); print!("<_PR_BR>");
@ -159,7 +160,6 @@ fn eval_suggest(
} }
fn get_rule(executable: &str) -> Option<String> { fn get_rule(executable: &str) -> Option<String> {
#[cfg(windows)] #[cfg(windows)]
let xdg_config_home = std::env::var("APPDATA").unwrap(); let xdg_config_home = std::env::var("APPDATA").unwrap();
#[cfg(not(windows))] #[cfg(not(windows))]
@ -181,7 +181,8 @@ fn get_rule(executable: &str) -> Option<String> {
return Some(file); return Some(file);
} }
#[cfg(not(windows))] { #[cfg(not(windows))]
{
let xdg_config_dirs = std::env::var("XDG_CONFIG_DIRS").unwrap_or("/etc/xdg".to_owned()); let xdg_config_dirs = std::env::var("XDG_CONFIG_DIRS").unwrap_or("/etc/xdg".to_owned());
let xdg_config_dirs = xdg_config_dirs.split(':').collect::<Vec<&str>>(); let xdg_config_dirs = xdg_config_dirs.split(':').collect::<Vec<&str>>();

View file

@ -249,7 +249,6 @@ pub fn exes(suggest: &mut String, exes_list: &mut Vec<TokenStream2>) {
} }
} else { } else {
unreachable!("Exes suggestion does not support range"); unreachable!("Exes suggestion does not support range");
} }
} else { } else {
unreachable!("Exes suggestion must have a command index"); unreachable!("Exes suggestion must have a command index");

View file

@ -138,7 +138,11 @@ pub fn find_similar(typo: &str, candidates: &[String], threshold: Option<usize>)
None None
} }
pub fn find_similars(typo: &str, candidates: &[String], threshold: Option<usize>) -> Option<Vec<String>> { pub fn find_similars(
typo: &str,
candidates: &[String],
threshold: Option<usize>,
) -> Option<Vec<String>> {
let threshold = threshold.unwrap_or(2); let threshold = threshold.unwrap_or(2);
let mut min_distance = typo.chars().count() / threshold + 1; let mut min_distance = typo.chars().count() / threshold + 1;
let mut min_distance_index = vec![]; let mut min_distance_index = vec![];
@ -156,7 +160,12 @@ pub fn find_similars(typo: &str, candidates: &[String], threshold: Option<usize>
} }
} }
if !min_distance_index.is_empty() { if !min_distance_index.is_empty() {
return Some(min_distance_index.iter().map(|&i| candidates[i].to_string()).collect()); return Some(
min_distance_index
.iter()
.map(|&i| candidates[i].to_string())
.collect(),
);
} }
None None
} }