diff --git a/Cargo.toml b/Cargo.toml index b0a615d..21ead14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pay_respects" -version = "0.3.1" +version = "0.3.3" edition = "2021" [dependencies] diff --git a/src/args.rs b/src/args.rs index d94c9c2..bde169a 100644 --- a/src/args.rs +++ b/src/args.rs @@ -44,7 +44,7 @@ pub fn handle_args() { .arg("echo $nu.config-path") .output() .expect("Failed to execute process"); - let config_path= String::from_utf8_lossy(&output.stdout); + let config_path = String::from_utf8_lossy(&output.stdout); let mut file = std::fs::OpenOptions::new() .write(true) .append(true) @@ -52,8 +52,8 @@ pub fn handle_args() { .expect("Failed to open config file"); writeln!(file, "{}", alias).expect("Failed to write to config file"); - }, - "n" | _ => std::process::exit(0), + } + _ => std::process::exit(0), }; std::process::exit(0); } diff --git a/src/corrections.rs b/src/corrections.rs index 3e54de1..6e6e9c2 100644 --- a/src/corrections.rs +++ b/src/corrections.rs @@ -73,9 +73,10 @@ fn check_condition(suggest: &str, command: &str, error_msg: &str) -> Option>(); + .split(',') + .collect::>(); for condition in conditions { let (mut condition, arg) = condition.split_once('(').unwrap(); @@ -133,15 +134,15 @@ fn eval_suggest(suggest: &str, last_command: &str) -> String { let start = { let mut start = start.parse::().unwrap_or(0); if start < 0 { - start = split_command.len() as i32 + start; - } + start += split_command.len() as i32; + } start as usize }; let end = { let mut end = end.parse::().unwrap_or(split_command.len() as i32 - 1) + 1; if end < 0 { - end = split_command.len() as i32 + end; - } + end += split_command.len() as i32; + } end as usize }; let command = split_command[start..end].join(" "); @@ -175,7 +176,7 @@ fn eval_suggest(suggest: &str, last_command: &str) -> String { .collect::>(); command_index = split[1].parse::().unwrap(); if command_index < 0 { - command_index = split_command(last_command).len() as i32 + command_index; + command_index += split_command(last_command).len() as i32; } } else { unreachable!("Typo suggestion must have a command index"); @@ -258,9 +259,7 @@ fn get_path_files() -> Vec { } fn get_directory_files(input: &str) -> Vec { - let mut input = input - .trim_matches(|c| c == '\'' || c == '"') - .to_owned(); + let mut input = input.trim_matches(|c| c == '\'' || c == '"').to_owned(); let files = loop { match std::fs::read_dir(&input) { Ok(files) => break files, diff --git a/src/main.rs b/src/main.rs index 4da25e6..0936de4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,5 +26,7 @@ fn main() { "No correction found for the command: {}\n", last_command.red().bold() ); - println!("If you think there should be a correction, please open an issue or send a pull request!"); + println!( + "If you think there should be a correction, please open an issue or send a pull request!" + ); } diff --git a/src/style.rs b/src/style.rs index 21c152f..13f7461 100644 --- a/src/style.rs +++ b/src/style.rs @@ -1,5 +1,5 @@ -use colored::*; use crate::corrections::split_command; +use colored::*; pub fn highlight_difference(corrected_command: &str, last_command: &str) -> String { let mut highlighted_command = String::new(); @@ -8,7 +8,7 @@ pub fn highlight_difference(corrected_command: &str, last_command: &str) -> Stri let split_last_command = split_command(last_command); for new in split_corrected_command { - if new == "" { + if new.is_empty() { continue; } let mut changed = true;