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
f1f7ed8dbe
commit
171b3d4607
5 changed files with 26 additions and 23 deletions
|
|
@ -37,7 +37,7 @@ pub fn opts(suggest: &mut String, last_command: &mut String, opt_list: &mut Vec<
|
|||
}
|
||||
}
|
||||
|
||||
pub fn cmd_reg(suggest: &mut String, last_command: &String) {
|
||||
pub fn cmd_reg(suggest: &mut String, last_command: &str) {
|
||||
while suggest.contains("{{cmd::") {
|
||||
let (placeholder, args) = eval_placeholder(suggest, "{{cmd::", "}}");
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ pub fn err(suggest: &mut String, error_msg: &str) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn command(suggest: &mut String, split_command: &Vec<String>) {
|
||||
pub fn command(suggest: &mut String, split_command: &[String]) {
|
||||
while suggest.contains("{{command") {
|
||||
let (placeholder, args) = eval_placeholder(suggest, "{{command", "}}");
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ pub fn command(suggest: &mut String, split_command: &Vec<String>) {
|
|||
if let Some((start, end)) = range.split_once(':') {
|
||||
let mut start_index = start.parse::<i32>().unwrap_or(0);
|
||||
if start_index < 0 {
|
||||
start_index = split_command.len() as i32 + start_index;
|
||||
start_index += split_command.len() as i32;
|
||||
};
|
||||
let mut end_index;
|
||||
let parsed_end = end.parse::<i32>();
|
||||
|
|
@ -76,9 +76,9 @@ pub fn command(suggest: &mut String, split_command: &Vec<String>) {
|
|||
} else {
|
||||
end_index = parsed_end.unwrap();
|
||||
if end_index < 0 {
|
||||
end_index = split_command.len() as i32 + end_index + 1;
|
||||
end_index += split_command.len() as i32 + 1;
|
||||
} else {
|
||||
end_index = end_index + 1;
|
||||
end_index += 1;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -89,12 +89,12 @@ pub fn command(suggest: &mut String, split_command: &Vec<String>) {
|
|||
let range = range.parse::<usize>().unwrap_or(0);
|
||||
let command = &split_command[range];
|
||||
|
||||
suggest.replace_range(placeholder, &command);
|
||||
suggest.replace_range(placeholder, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn typo(suggest: &mut String, split_command: &Vec<String>, shell: &str) {
|
||||
pub fn typo(suggest: &mut String, split_command: &[String], shell: &str) {
|
||||
while suggest.contains("{{typo") {
|
||||
let (placeholder, args) = eval_placeholder(suggest, "{{typo", "}}");
|
||||
|
||||
|
|
@ -138,8 +138,7 @@ pub fn typo(suggest: &mut String, split_command: &Vec<String>, shell: &str) {
|
|||
unreachable!("Typo suggestion must have a command index");
|
||||
};
|
||||
|
||||
let match_list;
|
||||
if suggest.contains('(') {
|
||||
let match_list = if suggest.contains('(') {
|
||||
let split = suggest[args.to_owned()]
|
||||
.split_once("(")
|
||||
.unwrap()
|
||||
|
|
@ -147,25 +146,24 @@ pub fn typo(suggest: &mut String, split_command: &Vec<String>, shell: &str) {
|
|||
.rsplit_once(")")
|
||||
.unwrap()
|
||||
.0;
|
||||
match_list = split.split(',').collect::<Vec<&str>>();
|
||||
split.split(',').collect::<Vec<&str>>()
|
||||
} else {
|
||||
unreachable!("Typo suggestion must have a match list");
|
||||
}
|
||||
};
|
||||
|
||||
let match_list = match_list
|
||||
.iter()
|
||||
.map(|s| s.trim().to_string())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
let command;
|
||||
if match_list[0].starts_with("{{shell") {
|
||||
let command = if match_list[0].starts_with("{{shell") {
|
||||
let function = match_list.join(",");
|
||||
let (_, args) = eval_placeholder(&function, "{{shell", "}}");
|
||||
let function = &function[args.to_owned()].trim_matches(|c| c == '(' || c == ')');
|
||||
command = suggest_typo(&split_command[index], eval_shell_command(shell, function));
|
||||
suggest_typo(&split_command[index], eval_shell_command(shell, function))
|
||||
} else {
|
||||
command = suggest_typo(&split_command[index], match_list);
|
||||
}
|
||||
suggest_typo(&split_command[index], match_list)
|
||||
};
|
||||
|
||||
suggest.replace_range(placeholder, &command);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,13 +55,14 @@ pub fn runtime_match(
|
|||
file = check_dirs(xdg_data_dirs);
|
||||
}
|
||||
|
||||
#[allow(clippy::question_mark)]
|
||||
if file.is_none() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let file = std::fs::read_to_string(file.unwrap()).unwrap();
|
||||
let rule: Rule = toml::from_str(&file).unwrap();
|
||||
let split_command = split_command(&last_command);
|
||||
let split_command = split_command(last_command);
|
||||
|
||||
let mut pure_suggest;
|
||||
|
||||
|
|
@ -132,7 +133,7 @@ fn eval_condition(
|
|||
shell: &str,
|
||||
last_command: &str,
|
||||
error_msg: &str,
|
||||
split_command: &Vec<String>,
|
||||
split_command: &[String],
|
||||
) -> bool {
|
||||
match condition {
|
||||
"executable" => check_executable(shell, arg),
|
||||
|
|
|
|||
|
|
@ -192,7 +192,6 @@ pub fn initialization(shell: &str, binary_path: &str, auto_alias: &str) {
|
|||
.expect("Failed to execute process");
|
||||
let config_path = String::from_utf8_lossy(&output.stdout);
|
||||
let mut file = std::fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.append(true)
|
||||
.open(config_path.trim())
|
||||
.expect("Failed to open config file");
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ pub fn suggest_typo(typos: &[String], candidates: Vec<String>) -> String {
|
|||
suggestions.join(" ")
|
||||
}
|
||||
|
||||
pub fn find_similar(typo: &str, candidates: &Vec<String>) -> Option<String> {
|
||||
pub fn find_similar(typo: &str, candidates: &[String]) -> Option<String> {
|
||||
let mut min_distance = 10;
|
||||
let mut min_distance_index = None;
|
||||
for (i, candidate) in candidates.iter().enumerate() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue