-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd-Path.bat
More file actions
68 lines (55 loc) · 1.64 KB
/
Add-Path.bat
File metadata and controls
68 lines (55 loc) · 1.64 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@echo off
setlocal EnableExtensions DisableDelayedExpansion
cmd /c exit /b 0
net session >nul 2>&1
if %errorLevel% == 0 (
goto :isAdmin
) else (
goto :elevate
)
:elevate
echo Elevating privileges...
echo Set UAC = CreateObject("Shell.Application") > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /b
:isAdmin
set "REPO_ROOT=%~dp0"
if "%REPO_ROOT:~-1%"=="\" set "REPO_ROOT=%REPO_ROOT:~0,-1%"
set "TARGET_DIR=%REPO_ROOT%\offgit\offgit\x64\Release"
echo Target directory to add to PATH:
echo "%TARGET_DIR%"
echo.
if not exist "%TARGET_DIR%" (
echo [ERROR] Could not find the release folder.
echo Make sure you compiled the project in Release mode first!
goto :end
)
for /f "tokens=2*" %%A in ('reg query HKCU\Environment /v PATH 2^>nul') do set "USER_PATH=%%B"
echo %USER_PATH% | findstr /I /C:";%TARGET_DIR%;" >nul && set "ALREADY_HERE=1"
echo %USER_PATH% | findstr /I /C:"%TARGET_DIR%;" >nul && set "ALREADY_HERE=1"
if "%ALREADY_HERE%"=="1" (
echo [INFO] This directory is already in your PATH.
goto :end
)
if "%USER_PATH%"=="" (
set "NEW_PATH=%TARGET_DIR%"
) else (
if "%USER_PATH:~-1%"==";" (
set "NEW_PATH=%USER_PATH%%TARGET_DIR%"
) else (
set "NEW_PATH=%USER_PATH%;%TARGET_DIR%"
)
)
reg add HKCU\Environment /v PATH /t REG_SZ /d "%NEW_PATH%" /f >nul
if %errorLevel% == 0 (
echo [SUCCESS] "%TARGET_DIR%" successfully added to PATH!
echo [NOTE] Restart your terminal/command prompt, then you can type 'offgit' anywhere.
) else (
echo [ERROR] Failed to update PATH.
)
:end
echo.
pause
exit /b