vscode/scripts/code.sh

83 lines
2.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2015-11-13 14:39:38 +01:00
2019-07-30 16:37:15 +02:00
set -e
2019-04-11 10:23:14 +02:00
2015-11-13 14:39:38 +01:00
if [[ "$OSTYPE" == "darwin"* ]]; then
realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; }
2017-02-21 21:22:01 +01:00
ROOT=$(dirname "$(dirname "$(realpath "$0")")")
2015-11-13 14:39:38 +01:00
else
2017-02-21 21:22:01 +01:00
ROOT=$(dirname "$(dirname "$(readlink -f $0)")")
2020-06-23 04:24:34 +02:00
# If the script is running in Docker using the WSL2 engine, powershell.exe won't exist
if grep -qi Microsoft /proc/version && type powershell.exe > /dev/null 2>&1; then
2019-04-11 10:23:14 +02:00
IN_WSL=true
fi
2015-11-13 14:39:38 +01:00
fi
2015-11-26 09:29:43 +01:00
function code() {
2017-02-21 21:22:01 +01:00
cd "$ROOT"
2015-11-13 14:39:38 +01:00
if [[ "$OSTYPE" == "darwin"* ]]; then
2016-08-09 17:56:05 +02:00
NAME=`node -p "require('./product.json').nameLong"`
CODE="./.build/electron/$NAME.app/Contents/MacOS/Electron"
else
NAME=`node -p "require('./product.json').applicationName"`
2016-08-09 17:57:09 +02:00
CODE=".build/electron/$NAME"
fi
# Get electron, compile, built-in extensions
if [[ -z "${VSCODE_SKIP_PRELAUNCH}" ]]; then
node build/lib/preLaunch.js
fi
2015-11-26 09:29:43 +01:00
2018-01-29 22:04:27 +01:00
# Manage built-in extensions
if [[ "$1" == "--builtin" ]]; then
exec "$CODE" build/builtin
return
fi
2015-11-26 09:29:43 +01:00
# Configuration
export NODE_ENV=development
export VSCODE_DEV=1
export VSCODE_CLI=1
2015-11-26 09:29:43 +01:00
export ELECTRON_ENABLE_STACK_DUMPING=1
export ELECTRON_ENABLE_LOGGING=1
2015-11-26 09:29:43 +01:00
# Launch Code
exec "$CODE" . "$@"
2015-11-26 09:29:43 +01:00
}
2019-04-11 10:23:14 +02:00
function code-wsl()
{
HOST_IP=$(echo "" | powershell.exe -noprofile -Command "& {(Get-NetIPAddress | Where-Object {\$_.InterfaceAlias -like '*WSL*' -and \$_.AddressFamily -eq 'IPv4'}).IPAddress | Write-Host -NoNewline}")
export DISPLAY="$HOST_IP:0"
2019-04-11 10:23:14 +02:00
# in a wsl shell
ELECTRON="$ROOT/.build/electron/Code - OSS.exe"
if [ -f "$ELECTRON" ]; then
local CWD=$(pwd)
cd $ROOT
2020-09-16 23:55:34 +02:00
export WSLENV=ELECTRON_RUN_AS_NODE/w:VSCODE_DEV/w:$WSLENV
2019-05-01 01:34:46 +02:00
local WSL_EXT_ID="ms-vscode-remote.remote-wsl"
local WSL_EXT_WLOC=$(echo "" | VSCODE_DEV=1 ELECTRON_RUN_AS_NODE=1 "$ROOT/.build/electron/Code - OSS.exe" "out/cli.js" --ms-enable-electron-run-as-node --locate-extension $WSL_EXT_ID)
cd $CWD
if [ -n "$WSL_EXT_WLOC" ]; then
# replace \r\n with \n in WSL_EXT_WLOC
local WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode-dev.sh
$WSL_CODE "$ROOT" "$@"
exit $?
else
echo "Remote WSL not installed, trying to run VSCode in WSL."
fi
2019-04-11 10:23:14 +02:00
fi
}
2021-06-07 20:38:43 +02:00
if [ "$IN_WSL" == "true" ] && [ -z "$DISPLAY" ]; then
2019-04-11 10:23:14 +02:00
code-wsl "$@"
2021-06-07 21:21:46 +02:00
elif [ -f /mnt/wslg/versions.txt ]; then
code --disable-gpu "$@"
else
code "$@"
fi
2021-06-07 21:21:46 +02:00
2021-06-07 20:38:43 +02:00
exit $?