git_override/scanpath.rs
1use is_executable::IsExecutable;
2use std::path::{Path, PathBuf};
3
4/// Find the absolute path for an executable on PATH
5pub fn scan_path<S>(exename: S) -> anyhow::Result<Vec<PathBuf>>
6where
7 S: AsRef<Path>,
8{
9 let mut found = vec![];
10
11 for dir in std::env::var("PATH")?.split(':') {
12 let dir: &Path = dir.as_ref();
13 let candidate = dir.join(exename.as_ref());
14 if candidate.is_executable() {
15 found.push(candidate.canonicalize()?);
16 }
17 }
18
19 Ok(found)
20}