Ensure web_config works on WSL (#7742)

* Ensure web_config works on WSL

web_config could sometimes fail on WSL if the user chose not to append
windows directories to their linux $PATH. This change ensures that the
cmd.exe executable is found in most cases even if windows directories
are not appended to $PATH on linux.

An error message letting the user know that cmd.exe was not found, and
that they should add the cmd.exe dir to their $PATH before running
fish_config is displayed if cmd.exe is still not found.

* Exit with a non 0 status code if cmd.exe is not found
This commit is contained in:
nosed1ve 2021-02-25 20:51:34 +05:30 committed by GitHub
parent 459ac2b566
commit aa608a42ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,6 +20,11 @@ import tempfile
import threading
from itertools import chain
COMMON_WSL_CMD_PATHS = (
"/mnt/c/Windows/System32",
"/windir/c/Windows/System32",
"/c/Windows/System32"
)
FISH_BIN_PATH = False # will be set later
IS_PY2 = sys.version_info[0] == 2
@ -33,8 +38,11 @@ else:
from urllib.parse import parse_qs
def find_executable(exe):
for p in os.environ["PATH"].split(os.pathsep):
def find_executable(exe, paths=()):
final_path = os.environ["PATH"].split(os.pathsep)
if paths:
final_path.extend(paths)
for p in final_path:
proposed_path = os.path.join(p, exe)
if os.access(proposed_path, os.X_OK):
return proposed_path
@ -1533,7 +1541,12 @@ def runThing():
if isMacOS10_12_5_OrLater():
subprocess.check_call(["open", fileurl])
elif is_wsl():
subprocess.call(["cmd.exe", "/c", "start %s" % url])
cmd_path = find_executable("cmd.exe", COMMON_WSL_CMD_PATHS)
if cmd_path:
subprocess.call([cmd_path, "/c", "start %s" % url])
else:
print("Please add the directory containing cmd.exe to your $PATH")
sys.exit(-1)
elif is_termux():
subprocess.call(["termux-open-url", url])
else: