Recognize ./scripts as a script directory

This commit is contained in:
Joshua McKinnon 2024-07-04 10:56:45 -07:00
parent 95c2ca0965
commit 7f03296e78
2 changed files with 8 additions and 3 deletions

View file

@ -127,10 +127,11 @@ pub fn discover_script_path(path: impl AsRef<str>, in_home_dir: bool) -> Result<
/** /**
Discovers a script file path based on a given script name, and tries to Discovers a script file path based on a given script name, and tries to
find scripts in `lune` and `.lune` folders if one was not directly found. find scripts in `lune`, `.lune` and `scripts` folders if one was not
directly found.
Note that looking in `lune` and `.lune` folders is automatically Note that looking in `lune`, `scripts` and `.lune` folders is
disabled if the given script name is an absolute path. automatically disabled if the given script name is an absolute path.
Behavior is otherwise exactly the same as for `discover_script_file_path`. Behavior is otherwise exactly the same as for `discover_script_file_path`.
*/ */
@ -148,6 +149,7 @@ pub fn discover_script_path_including_lune_dirs(path: &str) -> Result<PathBuf> {
// directories + the home directory for the current user // directories + the home directory for the current user
let res = discover_script_path(format!("lune{MAIN_SEPARATOR}{path}"), false) let res = discover_script_path(format!("lune{MAIN_SEPARATOR}{path}"), false)
.or_else(|_| discover_script_path(format!(".lune{MAIN_SEPARATOR}{path}"), false)) .or_else(|_| discover_script_path(format!(".lune{MAIN_SEPARATOR}{path}"), false))
.or_else(|_| discover_script_path(format!("scripts{MAIN_SEPARATOR}{path}"), false))
.or_else(|_| discover_script_path(format!("lune{MAIN_SEPARATOR}{path}"), true)) .or_else(|_| discover_script_path(format!("lune{MAIN_SEPARATOR}{path}"), true))
.or_else(|_| discover_script_path(format!(".lune{MAIN_SEPARATOR}{path}"), true)); .or_else(|_| discover_script_path(format!(".lune{MAIN_SEPARATOR}{path}"), true));

View file

@ -23,6 +23,9 @@ pub async fn find_lune_scripts(in_home_dir: bool) -> Result<Vec<(String, String)
if lune_dir.is_err() { if lune_dir.is_err() {
lune_dir = fs::read_dir(base_path.join(".lune")).await; lune_dir = fs::read_dir(base_path.join(".lune")).await;
} }
if lune_dir.is_err() && !in_home_dir {
lune_dir = fs::read_dir(base_path.join("scripts")).await;
}
match lune_dir { match lune_dir {
Ok(mut dir) => { Ok(mut dir) => {
let mut files = Vec::new(); let mut files = Vec::new();