mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-12 06:20:09 +01:00
chore: cleanup
This commit is contained in:
parent
3460d66aac
commit
ecdcee5969
4 changed files with 22 additions and 8 deletions
|
|
@ -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", "}}");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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>>();
|
||||||
|
|
||||||
|
|
@ -190,7 +191,7 @@ fn get_rule(executable: &str) -> Option<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let xdg_data_dirs =
|
let xdg_data_dirs =
|
||||||
std::env::var("XDG_DATA_DIRS").unwrap_or("/usr/local/share:/usr/share".to_owned());
|
std::env::var("XDG_DATA_DIRS").unwrap_or("/usr/local/share:/usr/share".to_owned());
|
||||||
let xdg_data_dirs = xdg_data_dirs.split(':').collect::<Vec<&str>>();
|
let xdg_data_dirs = xdg_data_dirs.split(':').collect::<Vec<&str>>();
|
||||||
|
|
||||||
if let Some(file) = check_dirs(&xdg_data_dirs) {
|
if let Some(file) = check_dirs(&xdg_data_dirs) {
|
||||||
|
|
|
||||||
|
|
@ -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");
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue