Use 'wslview' instead of 'xdg-open' on Windows

This commit is contained in:
Maxim Belkin 2023-02-27 08:18:12 +00:00
parent 06cf85ffd4
commit c9b289fc3d
4 changed files with 24 additions and 12 deletions

View File

@ -40,22 +40,12 @@ module SystemConfig
out
end
def wsl_version(kernel)
return unless /-microsoft/i.match?(kernel)
return "2 (Microsoft Store)" if Version.new(kernel[/Linux ([0-9.]*)-.*/, 1]) > Version.new("5.15")
return "2" if kernel.include?("-microsoft")
return "1" if kernel.include?("-Microsoft")
end
def dump_verbose_config(out = $stdout)
kernel = Utils.safe_popen_read("uname", "-mors").chomp
dump_generic_verbose_config(out)
out.puts "Kernel: #{kernel}"
out.puts "OS: #{OS::Linux.os_version}"
if (wsl = wsl_version(kernel).presence)
out.puts "WSL: #{wsl}"
end
out.puts "WSL: #{OS::Linux.wsl_version}" if OS::Linux.wsl?
out.puts "Host glibc: #{host_glibc_version}"
out.puts "/usr/bin/gcc: #{host_gcc_version}"
out.puts "/usr/bin/ruby: #{host_ruby_version}" if RUBY_PATH != HOST_RUBY_PATH

View File

@ -1,6 +1,8 @@
# typed: true
# frozen_string_literal: true
require "version"
# Helper functions for querying operating system information.
#
# @api private
@ -67,7 +69,7 @@ module OS
elsif OS.linux?
require "os/linux"
ISSUES_URL = "https://docs.brew.sh/Troubleshooting"
PATH_OPEN = "xdg-open"
PATH_OPEN = (OS::Linux.wsl? ? "wslview" : "xdg-open").freeze
end
sig { returns(T::Boolean) }

View File

@ -1,6 +1,8 @@
# typed: true
# frozen_string_literal: true
require "utils"
module OS
# Helper module for querying system information on Linux.
module Linux
@ -25,6 +27,23 @@ module OS
"Unknown"
end
end
sig { returns(T::Boolean) }
def wsl?
/-microsoft/i.match?(OS.kernel_version.to_s)
end
sig { returns(Version) }
def wsl_version
Version::NULL unless wsl?
kernel = OS.kernel_version.to_s
return Version.new("2 (Microsoft Store)") if Version.new(T.must(kernel[/^([0-9.]*)-.*/,
1])) > Version.new("5.15")
return Version.new("2") if kernel.include?("-microsoft")
return Version.new("1") if kernel.include?("-Microsoft")
Version::NULL
end
end
# rubocop:disable Style/Documentation

View File

@ -19,6 +19,7 @@ require "utils/repology"
require "utils/svn"
require "utils/tty"
require "tap_constants"
require "PATH"
module Homebrew
extend Context