Skip to content

Commit 251a490

Browse files
committed
run code wsl in dev
1 parent 5441e84 commit 251a490

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

scripts/code.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
set -e
4+
35
if [[ "$OSTYPE" == "darwin"* ]]; then
46
realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; }
57
ROOT=$(dirname "$(dirname "$(realpath "$0")")")
@@ -9,6 +11,9 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
911
export ELECTRON_ENABLE_LOGGING=1
1012
else
1113
ROOT=$(dirname "$(dirname "$(readlink -f $0)")")
14+
if grep -qi Microsoft /proc/version; then
15+
IN_WSL=true
16+
fi
1217
fi
1318

1419
function code() {
@@ -50,4 +55,23 @@ function code() {
5055
exec "$CODE" . "$@"
5156
}
5257

53-
code "$@"
58+
function code-wsl()
59+
{
60+
# in a wsl shell
61+
local WIN_CODE_CLI_CMD=$(wslpath -w "$ROOT/scripts/code-cli.bat")
62+
63+
local WSL_EXT_ID="ms-vscode.remote-wsl"
64+
local WSL_EXT_WLOC=$(cmd.exe /c "$WIN_CODE_CLI_CMD" --locate-extension $WSL_EXT_ID)
65+
if ! [ -z "$WSL_EXT_WLOC" ]; then
66+
# replace \r\n with \n in WSL_EXT_WLOC
67+
local WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode-dev.sh
68+
$WSL_CODE "$ROOT" "$@"
69+
exit $?
70+
fi
71+
}
72+
73+
if [ -z ${IN_WSL+x} ]; then
74+
code "$@"
75+
else
76+
code-wsl "$@"
77+
fi

0 commit comments

Comments
 (0)