Skip to content

Commit

Permalink
feat!: Ignore file endings
Browse files Browse the repository at this point in the history
  • Loading branch information
einfachIrgendwer0815 committed Sep 29, 2024
1 parent c075a6e commit 285ee36
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn find_script(name: &str, config: &Config) -> Result<Option<PathBuf>, 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<Vec<String>, io::Error> {
let mut set = HashSet::new();

Expand All @@ -108,7 +108,10 @@ pub fn all_scripts(config: &Config) -> Result<Vec<String>, 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;
Expand All @@ -129,7 +132,10 @@ pub fn all_scripts(config: &Config) -> Result<Vec<String>, io::Error> {
fn search_dir(name: &str, dir: &Path) -> Result<Option<PathBuf>, 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()));
Expand Down

0 comments on commit 285ee36

Please sign in to comment.