Seeker14491 / opener

Open a file or link in the system default program.
Apache License 2.0
54 stars 11 forks source link

Support WSL without requiring `wslview` or `xdg-open` #21

Open Seeker14491 opened 1 year ago

Seeker14491 commented 1 year ago

Currently on WSL we require either wslview or xdg-open to be available on the system, but there are WSL distros that don't include either preinstalled.

bugadani commented 1 year ago

Hi! Since this issue is about enhancing WSL support, I think this comment may be relevant here so I don't open a separate issue.

I just found your crate (I'm trying to open some generated stuff from WSL(2) and I've been reading a lot of cargo src to see how it opens docs) and it looks like open() has regressed in 0.6. With 0.5.2, I'm able to open a document in my browser, but the same code does not work on 0.6.

Seeker14491 commented 1 year ago

What is your wslu version (run wslview --version)? I think there were some relevant bug fixes in v4.1.0.

bugadani commented 1 year ago
$> wslview --version
wslu v2.3.6; wslview v06

This is an Ubuntu 20.04 that hasn't been updated in ages, to be honest.

Seeker14491 commented 1 year ago

Yeah, that version is 3+ years old. The current version works properly, though I would like to avoid regressions for people using older versions if possible.

tgross35 commented 10 months ago

This doesn't seem like it would be too bad. The file is pretty simple, and wslview --verbose ... tells you exactly what it is doing. Link: https://github.com/wslutilities/wslu/blob/b6fa4b70b22909337cb13b5b2ea9845f733f60ff/src/wslview.sh

E.g. wslview --verbose http://google.com just calls powershell

/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NonInteractive $'\342\200\223ExecutionPolicy' Bypass -Command '[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Console]::InputEncoding = [System.Text.Encoding]::GetEncoding(437); Start' '"http://google.com"'

And opening a file:

/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NonInteractive $'\342\200\223ExecutionPolicy' Bypass -Command '[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Console]::InputEncoding = [System.Text.Encoding]::GetEncoding(437); Start' '"\\wsl$\Ubuntu"'

Opening a html file in browser just works

/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NonInteractive $'\342\200\223ExecutionPolicy' Bypass -Command '[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Console]::InputEncoding = [System.Text.Encoding]::GetEncoding(437); Start' '"\\wsl$\Ubuntu\home\tmgross\foo\target\doc\foo\index.html"'