1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::path::PathBuf;
pub fn get_from_path(exe_name: &str) -> Option<PathBuf> {
std::env::var_os("PATH").and_then(|paths| {
std::env::split_paths(&paths).find_map(|dir| {
let bash_path = dir.join(exe_name);
if bash_path.is_file() {
Some(bash_path)
} else {
None
}
})
})
}
pub fn get_sh() -> Option<PathBuf> {
let exe_name = if cfg!(target_os = "windows") {
"bash.exe"
} else {
"sh"
};
if cfg!(target_os = "windows") {
let git_path = get_from_path("git.exe").expect("Couldn't find git.exe");
let git_dir = git_path.parent().unwrap().parent().unwrap();
let git_bash = git_dir.join("bin").join(exe_name);
if git_bash.is_file() {
return Some(git_bash);
}
}
get_from_path(exe_name)
}