[F] Fix bash in MINGW64
This commit is contained in:
@@ -322,31 +322,53 @@ where
|
|||||||
/// Gets the absolute path of the bash command.
|
/// Gets the absolute path of the bash command.
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn bash_path() -> Result<PathBuf> {
|
fn bash_path() -> Result<PathBuf> {
|
||||||
// Find `bash.exe` in `PATH`, but exclude the known bad paths
|
// 1. Try to find a good bash.exe in PATH
|
||||||
if let Some(bash_path) = find_in_path("bash.exe").context("bash.exe not found")? {
|
let bash_in_path = find_in_path("bash.exe").unwrap_or(None);
|
||||||
// Check if it's not MSYS bash https://stackoverflow.com/a/58418686/1529493
|
if let Some(pth) = &bash_in_path {
|
||||||
if !bash_path.ends_with(r"Git\usr\bin\bash.exe") {
|
// Check if it's not WSL bash
|
||||||
// Check if it's not WSL bash
|
// See https://github.com/hykilpikonna/hyfetch/issues/233
|
||||||
// See https://github.com/hykilpikonna/hyfetch/issues/233
|
let is_wsl = (|| {
|
||||||
let windir = env::var_os("windir").context("`windir` environ not found")?;
|
let windir = env::var_os("windir")?;
|
||||||
match is_same_file(&bash_path, Path::new(&windir).join(r"System32\bash.exe")) {
|
let wsl_bash = Path::new(&windir).join(r"System32\bash.exe");
|
||||||
Ok(false) => return Ok(bash_path),
|
Some(is_same_file(pth, &wsl_bash).unwrap_or(false))
|
||||||
Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(bash_path),
|
})()
|
||||||
_ => {}
|
.unwrap_or(false);
|
||||||
|
|
||||||
|
if !is_wsl {
|
||||||
|
// Check if it's not MSYS bash https://stackoverflow.com/a/58418686/1529493
|
||||||
|
// We prefer the Git wrapper bash if possible, but we'll accept this if it's all we have.
|
||||||
|
if !pth.ends_with(r"Git\usr\bin\bash.exe") {
|
||||||
|
return Ok(pth.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(bash_path) = find_in_path("git.exe").context("failed to find `git.exe` in `PATH`")? {
|
// 2. Try to find git.exe in PATH and look for bash.exe relative to it
|
||||||
if bash_path.ends_with(r"Git\cmd\git.exe") {
|
if let Ok(Some(git_path)) = find_in_path("git.exe") {
|
||||||
let pth = bash_path.parent().unwrap().parent().unwrap().join(r"bin\bash.exe");
|
let mut current = git_path.clone();
|
||||||
if pth.is_file() {
|
for _ in 0..3 {
|
||||||
return Ok(pth);
|
if let Some(parent) = current.parent() {
|
||||||
|
let bin_bash = parent.join(r"bin\bash.exe");
|
||||||
|
if bin_bash.is_file() {
|
||||||
|
return Ok(bin_bash);
|
||||||
|
}
|
||||||
|
let usr_bin_bash = parent.join(r"usr\bin\bash.exe");
|
||||||
|
if usr_bin_bash.is_file() {
|
||||||
|
return Ok(usr_bin_bash);
|
||||||
|
}
|
||||||
|
current = parent.to_path_buf();
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(anyhow!("bash.exe not found"))
|
// 3. Fallback to whatever bash we found in PATH (even if it was the MSYS one)
|
||||||
|
if let Some(pth) = bash_in_path {
|
||||||
|
return Ok(pth);
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(anyhow!("bash.exe not found. Please ensure Git for Windows is installed and in your PATH."))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs neofetch command, returning the piped stdout output.
|
/// Runs neofetch command, returning the piped stdout output.
|
||||||
|
|||||||
Reference in New Issue
Block a user