From 3b2000e1a0783b87b57c7b62090627ed44c88519 Mon Sep 17 00:00:00 2001 From: phlowx Date: Fri, 29 Mar 2024 05:01:09 +0100 Subject: [PATCH] Modification of the --hyperlink parameter so that it also works in a WSL environment. 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} --- 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..32824f4f4 100644 --- a/src/output/file_name.rs +++ b/src/output/file_name.rs @@ -1,5 +1,6 @@ use std::fmt::Debug; use std::path::Path; +use std::env; use nu_ansi_term::{AnsiString as ANSIString, Style}; use path_clean; @@ -396,9 +397,12 @@ 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 = match env::var("WSL_DISTRO_NAME") { + Ok(distro_name) => format!("{HYPERLINK_START}file://wsl$/{distro_name}{abs_path}{HYPERLINK_END}"), + Err(_) => format!("{HYPERLINK_START}file://{abs_path}{HYPERLINK_END}") + }; + + bits.push(ANSIString::from(hyperlink)); display_hyperlink = true; }