Skip to content

Commit

Permalink
Modification of the --hyperlink parameter so that it also works in a …
Browse files Browse the repository at this point in the history
…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}
  • Loading branch information
phlowx committed Mar 29, 2024
1 parent b9dfd61 commit 3b2000e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/output/file_name.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3b2000e

Please sign in to comment.