chore: cleanup

This commit is contained in:
iff 2025-01-04 22:30:19 +01:00
parent 81ca8d6e98
commit 5791c2fc20
6 changed files with 28 additions and 31 deletions

View file

@ -32,7 +32,6 @@ pub fn suggest_candidates(data: &mut Data) {
thread::scope(|s| {
s.spawn(|| {
let command = &data.command;
for module in modules {
let new_candidates = module_output(&data, module);

View file

@ -21,6 +21,8 @@
### Entertaining
- Select library that works well with `pay-respects`' complex difference highlighting
- Select library that:
- Works well with `pay-respects`' complex difference highlighting
- Supports adding candidates dynamically
- NLP model as alternative to the current LLM based AI requests

View file

@ -147,19 +147,12 @@ fn eval_suggest(
}
fn get_rule(executable: &str) -> Option<String> {
let xdg_config_home = if cfg!(windows) {
std::env::var("APPDATA").unwrap()
} else {
std::env::var("XDG_CONFIG_HOME")
.unwrap_or_else(|_| std::env::var("HOME").unwrap() + "/.config")
};
let user_rule_dir = format!("{}/pay-respects/rules", xdg_config_home);
let user_rule_file = format!("{}/{}.toml", user_rule_dir, executable);
if std::path::Path::new(&user_rule_file).exists() {
return Some(user_rule_file);
}
#[cfg(windows)]
let xdg_config_home = std::env::var("APPDATA").unwrap();
#[cfg(not(windows))]
let xdg_config_home = std::env::var("XDG_CONFIG_HOME")
.unwrap_or_else(|_| std::env::var("HOME").unwrap() + "/.config");
let check_dirs = |dirs: &[&str]| -> Option<String> {
for dir in dirs {
@ -172,20 +165,25 @@ fn get_rule(executable: &str) -> Option<String> {
None
};
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>>();
if let Some(file) = check_dirs(&xdg_config_dirs) {
if let Some(file) = check_dirs(&[&xdg_config_home]) {
return Some(file);
}
let xdg_data_dirs =
#[cfg(not(windows))] {
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>>();
if let Some(file) = check_dirs(&xdg_config_dirs) {
return Some(file);
}
let xdg_data_dirs =
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) {
return Some(file);
if let Some(file) = check_dirs(&xdg_data_dirs) {
return Some(file);
}
}
None
}

View file

@ -5,7 +5,7 @@ pattern = [
"command not found",
"unknown command",
"nu::shell::external_command",
"is not recognized as a name of a cmdlet, function, script file, or executable program"
"is not recognized as a name of a cmdlet"
]
suggest = [
'''

View file

@ -56,7 +56,7 @@ workspaces
[[match_err]]
pattern = [
"error `install` has been replaced with `add` to add new dependencies."
"`install` has been replaced with `add`"
]
suggest = [
'''

View file

@ -7,9 +7,8 @@ use crate::evals::find_similar;
pub fn get_path_files() -> Vec<String> {
let path_env = path_env();
if cfg!(debug_assertions) {
eprintln!("path_env: {path_env}");
}
#[cfg(debug_assertions)]
eprintln!("path_env: {path_env}");
let path_env_sep = path_env_sep();
@ -50,9 +49,8 @@ pub fn get_path_files() -> Vec<String> {
pub fn best_match_file(input: &str) -> Option<String> {
let mut input = input.trim_matches(|c| c == '\'' || c == '"').to_owned();
if cfg!(debug_assertions) {
eprintln!("best_match_file input: {input}");
}
#[cfg(debug_assertions)]
eprintln!("best_match_file input: {input}");
let mut exit_dirs = Vec::new();
let mut files = loop {
match std::fs::read_dir(&input) {