fix: relative path rules

This commit is contained in:
iff 2024-12-09 17:06:00 +01:00
parent b332ca4dfb
commit ee7b270d9c
4 changed files with 14 additions and 3 deletions

View file

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Aliases matching to command-not-found
- Relative path command fixes
- Does not work in `bash` and `zsh`: Not considered a command
### Changed

View file

@ -10,7 +10,7 @@ use crate::shell::{add_candidates_no_dup, module_output, shell_evaluated_command
use crate::style::highlight_difference;
pub fn suggest_candidates(data: &mut Data) {
let executable = &data.split[0];
let executable = &data.split[0].rsplit(std::path::MAIN_SEPARATOR).next().unwrap();
let command = &data.command;
let privilege = &data.privilege;
let mut suggest_candidates = vec![];

View file

@ -1,6 +1,6 @@
[package]
name = "pay-respects-utils"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
# for crates.io

View file

@ -76,6 +76,14 @@ pub fn suggest_typo(typos: &[String], candidates: Vec<String>, executables: &[St
if candidates.len() == 1 {
match candidates[0].as_str() {
"path" => {
if typo.contains(std::path::MAIN_SEPARATOR) {
if let Some(suggest) = best_match_file(typo) {
suggestions.push(suggest);
} else {
suggestions.push(typo.to_string());
}
continue;
}
if let Some(suggest) = find_similar(typo, executables, Some(2)) {
suggestions.push(suggest);
} else {
@ -89,7 +97,9 @@ pub fn suggest_typo(typos: &[String], candidates: Vec<String>, executables: &[St
suggestions.push(typo.to_string());
}
}
_ => {}
_ => {
unreachable!("suggest_typo: must have at least two candidates")
}
}
} else if let Some(suggest) = find_similar(typo, &candidates, Some(2)) {
suggestions.push(suggest);