Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make hyperlinks usable inside a WSL environment (support all paths) #925

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

opalmay
Copy link

@opalmay opalmay commented Apr 9, 2024

Following the discussion in #913 ,
This solution supports both types of paths, Linux and Windows mounted.

When a path is under /mnt/{drive_letter}, it constructs the equivalent Windows path. Otherwise, the path is simply prefixed to indicate WSL.

@opalmay opalmay requested a review from PThorpe92 as a code owner April 9, 2024 15:58
src/output/file_name.rs Outdated Show resolved Hide resolved
@opalmay opalmay force-pushed the feat_wsl_hyperlinks branch 3 times, most recently from 7c46306 to 8f09929 Compare April 10, 2024 08:18
@gierens gierens requested review from daviessm and gierens July 9, 2024 13:45
@cafkafk cafkafk force-pushed the feat_wsl_hyperlinks branch from 94fd70b to d59c615 Compare October 18, 2024 14:20
Comment on lines +435 to +459
let distro_name = std::env::var("WSL_DISTRO_NAME").ok();
let path = if let Some(distro_name) = distro_name {
if abs_path.starts_with("/mnt/") {
let parts: Vec<&str> = abs_path.split('/').collect();
if parts.len() > 2
&& parts[2].len() == 1
&& parts[2].chars().next().unwrap().is_ascii_alphabetic()
{
let mut windows_path = format!("{}:\\", parts[2].to_uppercase());
for part in &parts[3..] {
if !part.is_empty() {
windows_path.push_str(part);
windows_path.push('\\');
}
}
windows_path
} else {
format!("wsl$/{distro_name}{abs_path}")
}
} else {
format!("wsl$/{distro_name}{abs_path}")
}
} else {
abs_path
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if this code was written in a less nested way, the level of indentation makes it hard to read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

5 participants