From 0a36179fbe1c7f80f45fc2371c8d7c0a084635e1 Mon Sep 17 00:00:00 2001 From: phlowx Date: Fri, 29 Mar 2024 05:01:09 +0100 Subject: [PATCH] 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 Co-authored-by: Sandro-Alessio Gierens --- src/output/file_name.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/output/file_name.rs b/src/output/file_name.rs index 30c88a93c..a77c7bb75 100644 --- a/src/output/file_name.rs +++ b/src/output/file_name.rs @@ -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; }