From 285ee3687c2b0eae265a86ba8afe7cfdf4079319 Mon Sep 17 00:00:00 2001 From: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com> Date: Sat, 28 Sep 2024 13:25:12 +0200 Subject: [PATCH] feat!: Ignore file endings --- src/scripts.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/scripts.rs b/src/scripts.rs index 0dc0412..ce2e760 100644 --- a/src/scripts.rs +++ b/src/scripts.rs @@ -86,7 +86,7 @@ pub fn find_script(name: &str, config: &Config) -> Result, io::E /// Get names of all available scripts. /// -/// Note: the returned values are script *names* not paths. +/// Note: the returned values are script *names* without file endings. pub fn all_scripts(config: &Config) -> Result, io::Error> { let mut set = HashSet::new(); @@ -108,7 +108,10 @@ pub fn all_scripts(config: &Config) -> Result, io::Error> { let entry = entry?; if entry.file_type()?.is_file() { - let file_name = entry.file_name().to_string_lossy().into_owned(); + let file_name = match entry.path().file_stem() { + Some(stem) => stem.to_string_lossy().into_owned(), + None => continue, + }; if file_name.starts_with('.') { continue; @@ -129,7 +132,10 @@ pub fn all_scripts(config: &Config) -> Result, io::Error> { fn search_dir(name: &str, dir: &Path) -> Result, io::Error> { for entry in fs::read_dir(dir)? { let entry = entry?; - let file_name = entry.file_name().to_string_lossy().into_owned(); + let file_name = match entry.path().file_stem() { + Some(stem) => stem.to_string_lossy().into_owned(), + None => continue, + }; if file_name == name && entry.file_type()?.is_file() && !file_name.starts_with('.') { return Ok(Some(entry.path()));