-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVSCode.cmd
More file actions
47 lines (42 loc) · 1.38 KB
/
Copy pathVSCode.cmd
File metadata and controls
47 lines (42 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@echo off
setlocal
REM Resolve this script's directory as the repo root.
set "REPO_DIR=%~dp0"
if "%REPO_DIR:~-1%"=="\" set "REPO_DIR=%REPO_DIR:~0,-1%"
REM Prefer a resolved Code.exe from PATH entries (including code.cmd wrappers).
set "CODE_EXE="
for /f "usebackq delims=" %%I in (`where code 2^>nul`) do (
if /I "%%~xI"==".exe" (
set "CODE_EXE=%%~fI"
goto :launch
)
if /I "%%~xI"==".cmd" (
if exist "%%~dpI..\Code.exe" (
set "CODE_EXE=%%~dpI..\Code.exe"
goto :launch
)
)
)
REM Fallback to common Windows install locations.
for %%I in (
"%LocalAppData%\Programs\Microsoft VS Code\Code.exe"
"%ProgramFiles%\Microsoft VS Code\Code.exe"
"%ProgramFiles(x86)%\Microsoft VS Code\Code.exe"
) do (
if exist %%~I (
set "CODE_EXE=%%~I"
goto :launch
)
)
:launch
if defined CODE_EXE (
powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "Start-Process -FilePath $env:CODE_EXE -WorkingDirectory $env:REPO_DIR -ArgumentList @('-n', $env:REPO_DIR)"
if errorlevel 1 (
echo Failed to launch VS Code from "%CODE_EXE%".
exit /b 1
)
exit /b 0
)
echo Could not find VS Code. Install it or add the ^"code^" command to PATH.
echo In VS Code: press Ctrl+Shift+P and run ^"Shell Command: Install 'code' command in PATH^".
exit /b 1