-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.bat
50 lines (46 loc) · 1.45 KB
/
config.bat
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
@echo off
setlocal enabledelayedexpansion
set cwd=%~dp0
:: 2. Add user env variable %SHELL4WIN%
set usrName=%USERDOMAIN%\\%USERNAME%
echo.
echo set env variable for %usrName%
echo.
set envName=SHELL4WIN
wmic ENVIRONMENT create name="%envName%", username="%usrName%", VariableValue="%cwd%" > nul 2>&1 || (
wmic ENVIRONMENT where "name='%envName%' and username='%usrName%'" set VariableValue="%cwd%"
echo %envName% already set.
)
echo.
echo set SHELL4WIN=%cwd%
echo.
:: 3. Add bin paths to user env %PATH%
for /f "tokens=2 delims==" %%a in (
'wmic ENVIRONMENT where "UserName='%usrName%' and name='PATH'" get VariableValue /value'
) do set usrPath=%%a
set usrPath=%usrPath%
if "!usrPath!" == "" (
wmic ENVIRONMENT create name="PATH", username="%usrName%", VariableValue=""
)
echo PATH(before)=!usrPath!
echo.
set parent=%cwd:~-10%
for /d %%f in (*) do (
echo %%f | findstr /b "\." > nul || (
echo !usrPath! | findstr "!parent!%%f" > nul || (
set usrPath=!usrPath!%%SHELL4WIN%%%%f;
echo PATH append %%SHELL4WIN%%%%f;
)
)
)
wmic ENVIRONMENT where "name='PATH' and username='%usrName%'" set VariableValue="!usrPath!"
echo.
echo PATH(after)=!usrPath!
echo.
:: 4. Add user env variable
wmic ENVIRONMENT create name="LS_OPTIONS", username="%usrName%", VariableValue="-bhC --color=auto"> nul 2>&1 || echo LS_OPTIONS already set.
:: Restart explorer to make it work
taskkill /im explorer.exe /f
start explorer.exe
echo on
pause