Skip to content

Commit

Permalink
fix(output): modify --hyperlink output to work properly in WSL
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Sandro-Alessio Gierens <[email protected]>
  • Loading branch information
phlowx and gierens committed Mar 29, 2024
1 parent b9dfd61 commit 0a36179
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
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0a36179

Please sign in to comment.