Skip to content

Commit 04421fe

Browse files
pankgeorgpfitzsebmortenpi
authored
feat(wsl): detect wsl (#36)
Co-authored-by: Sebastian Pfitzner <[email protected]> Co-authored-by: Morten Piibeleht <[email protected]>
1 parent 82012a2 commit 04421fe

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PkgAuthentication"
22
uuid = "4722fa14-9d28-45f9-a1e2-a38605bd88f0"
33
authors = ["Sebastian Pfitzner", "contributors"]
4-
version = "2.0.3"
4+
version = "2.1.0"
55

66
[deps]
77
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"

src/PkgAuthentication.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Pkg
66
import Random
77
import TOML
88

9+
include("helpers.jl")
10+
911
const pkg_server_env_var_name = "JULIA_PKG_SERVER"
1012

1113
## abstract state types
@@ -520,8 +522,8 @@ function open_browser(url::AbstractString)
520522
@debug "error executing browser hook" exception=(err, catch_backtrace())
521523
return false
522524
end
523-
elseif Sys.iswindows()
524-
run(`cmd /c "start $url"`; wait=false)
525+
elseif Sys.iswindows() || detectwsl()
526+
run(`cmd.exe /c "start $url"`; wait=false)
525527
elseif Sys.isapple()
526528
run(`open $url`; wait=false)
527529
elseif Sys.islinux() || Sys.isbsd()

src/helpers.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@static if isdefined(Sys, :detectwsl)
2+
const detectwsl = Sys.detectwsl
3+
else
4+
# Borrowed from Julia (MIT license)
5+
# https://github.com/JuliaLang/julia/blob/726c816b9590d748345fb615b76b685c79eafd0d/base/sysinfo.jl#L549-L555
6+
# https://github.com/JuliaLang/julia/pull/57069
7+
function detectwsl()
8+
# We use the same approach as canonical/snapd do to detect WSL
9+
islinux() && (
10+
isfile("/proc/sys/fs/binfmt_misc/WSLInterop")
11+
|| isdir("/run/WSL")
12+
)
13+
end
14+
end

0 commit comments

Comments
 (0)