Use system web browser under WSL

Launch `cmd.exe /c "start URL"` under WSL for both `fish_config` and
`help`. This works around #4299 but does not address the underlying
issue (#1132).
This commit is contained in:
Mahmoud Al-Qudsi 2018-04-02 18:36:11 -05:00
parent 358e9def5b
commit 99ecaec175
2 changed files with 18 additions and 1 deletions

View file

@ -119,6 +119,11 @@ function help --description 'Show help for the fish shell'
set fish_help_page "index.html"
end
set -l wsl 0
if uname -a | string match -qr Microsoft
set wsl 1
end
set -l page_url
if test -f $__fish_help_dir/index.html
# Help is installed, use it
@ -150,8 +155,10 @@ function help --description 'Show help for the fish shell'
end
end
if test $wsl -eq 1
cmd.exe /c "start $page_url"
# If browser is known to be graphical, put into background
if contains -- $fish_browser[1] $graphical_browsers
else if contains -- $fish_browser[1] $graphical_browsers
switch $fish_browser[1]
case 'htmlview' 'x-www-browser'
printf (_ 'help: Help is being displayed in your default browser.\n')

View file

@ -35,6 +35,14 @@ def isMacOS10_12_5_OrLater():
version = platform.mac_ver()[0]
return version and LooseVersion(version) >= LooseVersion('10.12.5')
def is_wsl():
""" Return whether we are running under the Windows Subsystem for Linux """
if 'linux' in platform.system().lower():
with open('/proc/version', 'r') as f:
if 'Microsoft' in f.read():
return True
return False
# Disable CLI web browsers
term = os.environ.pop('TERM', None)
@ -1139,6 +1147,8 @@ fileurl = 'file://' + filename
print("Web config started at '%s'. Hit enter to stop." % fileurl)
if isMacOS10_12_5_OrLater():
subprocess.check_call(['open', fileurl])
elif is_wsl():
subprocess.call(['cmd.exe', '/c', "start %s" % url])
else:
webbrowser.open(fileurl)