Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/resources/win32/bin/code.sh
3274 views
1
#!/usr/bin/env sh
2
#
3
# Copyright (c) Microsoft Corporation. All rights reserved.
4
# Licensed under the MIT License. See License.txt in the project root for license information.
5
if [ "$VSCODE_WSL_DEBUG_INFO" = true ]; then
6
set -x
7
fi
8
9
COMMIT="@@COMMIT@@"
10
APP_NAME="@@APPNAME@@"
11
QUALITY="@@QUALITY@@"
12
NAME="@@NAME@@"
13
SERVERDATAFOLDER="@@SERVERDATAFOLDER@@"
14
VSCODE_PATH="$(dirname "$(dirname "$(realpath "$0")")")"
15
ELECTRON="$VSCODE_PATH/$NAME.exe"
16
17
IN_WSL=false
18
if [ -n "$WSL_DISTRO_NAME" ]; then
19
# $WSL_DISTRO_NAME is available since WSL builds 18362, also for WSL2
20
IN_WSL=true
21
else
22
WSL_BUILD=$(uname -r | sed -E 's/^[0-9.]+-([0-9]+)-Microsoft.*|.*/\1/')
23
if [ -n "$WSL_BUILD" ]; then
24
if [ "$WSL_BUILD" -ge 17063 ]; then
25
# WSLPATH is available since WSL build 17046
26
# WSLENV is available since WSL build 17063
27
IN_WSL=true
28
else
29
# If running under older WSL, don't pass cli.js to Electron as
30
# environment vars cannot be transferred from WSL to Windows
31
# See: https://github.com/microsoft/BashOnWindows/issues/1363
32
# https://github.com/microsoft/BashOnWindows/issues/1494
33
"$ELECTRON" "$@"
34
exit $?
35
fi
36
fi
37
fi
38
if [ $IN_WSL = true ]; then
39
40
export WSLENV="ELECTRON_RUN_AS_NODE/w:$WSLENV"
41
CLI=$(wslpath -m "$VSCODE_PATH/resources/app/out/cli.js")
42
43
# use the Remote WSL extension if installed
44
WSL_EXT_ID="ms-vscode-remote.remote-wsl"
45
46
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --locate-extension $WSL_EXT_ID >/tmp/remote-wsl-loc.txt 2>/dev/null </dev/null
47
WSL_EXT_WLOC=$(cat /tmp/remote-wsl-loc.txt)
48
49
if [ -n "$WSL_EXT_WLOC" ]; then
50
# replace \r\n with \n in WSL_EXT_WLOC
51
WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh
52
"$WSL_CODE" "$COMMIT" "$QUALITY" "$ELECTRON" "$APP_NAME" "$SERVERDATAFOLDER" "$@"
53
exit $?
54
fi
55
56
elif [ -x "$(command -v cygpath)" ]; then
57
CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js")
58
else
59
CLI="$VSCODE_PATH/resources/app/out/cli.js"
60
fi
61
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
62
exit $?
63
64