fix(output): modify --hyperlink output to work properly in WSL

If the environment variable "$WSL_DISTRO_NAME" is set, the hyperlink is
modified so that the file/folder can be opened directly via Windows Explorer.

To open a file in a WSL environmen the link must be as follows:
file://wsl$/${WSL_DISTRO_NAME}/{abs_path}

Co-authored-by: phlowx <phlowx@googlemail.com>
Co-authored-by: Sandro-Alessio Gierens <sandro@gierens.de>
This commit is contained in:
phlowx 2024-03-29 05:01:09 +01:00 committed by Sandro-Alessio Gierens
parent b9dfd61723
commit 0a36179fbe

View file

@ -396,9 +396,13 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
#[cfg(target_os = "windows")]
let abs_path = abs_path.strip_prefix("\\\\?\\").unwrap_or(&abs_path);
bits.push(ANSIString::from(format!(
"{HYPERLINK_START}file://{abs_path}{HYPERLINK_END}"
)));
let hyperlink = if let Ok(distro_name) = std::env::var("WSL_DISTRO_NAME") {
format!("{HYPERLINK_START}file://wsl$/{distro_name}{abs_path}{HYPERLINK_END}")
} else {
format!("{HYPERLINK_START}file://{abs_path}{HYPERLINK_END}")
};
bits.push(ANSIString::from(hyperlink));
display_hyperlink = true;
}