-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshellenv.bat
152 lines (110 loc) · 3.51 KB
/
shellenv.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
:: This file is a helper script to simplify setting up of the %PATH% and
:: other useful environment variables.
@echo off
:: Tea-Set
for /f "tokens=*" %%p in ( "%~dp0." ) do set "TEA_HOME=%%~fp"
:: Java
call :ifexist "%~dp0javaenv.bat"
call :shellenv.config
call :shellenv.conemu
goto :EOF
:: ========================================================================
:ifexist
if exist "%~1" call %*
goto :EOF
:: ========================================================================
:shellenv.config
if not exist "%~dpn0.cfg" goto :EOF
setlocal enabledelayedexpansion
:: This is TAB separated file
for /f "usebackq eol=; tokens=1,2,3,4 delims= " %%1 in ( "%~dpn0.cfg" ) do (
if /i "%%~1" == "ROOT" (
for /f "tokens=*" %%p in ( 'echo:%%~2' ) do set "auto_root=%%~fp"
) else if /i "%%~1" == "HOME" (
call :shellenv.set.home "%%~2" "%%~3"
) else if /i "%%~1" == "DIRS" (
call :shellenv.set.dirs "!auto_root!\%%~2" "%%~3" "%%~4"
) else if /i "%%~1" == "DIR" (
call :shellenv.set.dir "!auto_root!\%%~2" "%%~3"
)
)
endlocal & set "PATH=%PATH%"
goto :EOF
:: ========================================================================
:: homedir [prepend]
:shellenv.set.home
call :shellenv.set.dirs "%~1" "bin;sbin;usr\bin" "%~2"
goto :EOF
:: ========================================================================
:: rootdir\dir subdirs [prepend]
:shellenv.set.dirs
if "%~1" == "" goto :EOF
if "%~2" == "" goto :EOF
setlocal enabledelayedexpansion
set "auto_subdirs=%~2"
set "auto_path="
for %%s in ( "%auto_subdirs:;=" "%" ) do for %%p in ( "%~1\%%~s" ) do (
call :shellenv.check.dir "%%~fp" && set "auto_path=!auto_path!;%%~fp"
)
if defined auto_path set "auto_path=!auto_path:~1!"
call :shellenv.concat "%~3"
endlocal & set "PATH=%PATH%"
goto :EOF
:: ========================================================================
:: rootdir\dir [prepend]
:shellenv.set.dir
if "%~1" == "" goto :EOF
setlocal
set "auto_path="
for %%p in (
"%~1\bin"
"%~1\usr\bin"
"%~1\cmd"
"%~1"
) do if not defined auto_path (
call :shellenv.check.dir "%%~fp" && set "auto_path=%%~fp"
)
if not defined auto_path goto :EOF
call :shellenv.concat "%~2"
endlocal & set "PATH=%PATH%"
goto :EOF
:: ========================================================================
:: dir
:shellenv.check.dir
:: Skip if path not exists
if not exist "%~1" exit /b 1
:: Skip if the path is specified in %PATH%
for %%p in ( "%PATH:;=" "%" ) do if /i "%~1" == "%%~p" exit /b 1
:: Skip if no executables in the path
dir /b /a-d "%~1\*.exe" "%~1\*.bat" "%~1\*.cmd" >nul 2>nul
goto :EOF
:: ========================================================================
:: [prepend]
:shellenv.concat
if not defined auto_path goto :EOF
if /i "%~1" == "prepend" (
set "PATH=%auto_path%;%PATH%"
) else (
set "PATH=%PATH%;%auto_path%"
)
goto :EOF
:: ========================================================================
:shellenv.conemu
:: If possible, move the cursor to the bottom of the screen
if /i "%ConEmuANSI%" == "ON" (
echo:[99999;1H
) else (
reg query "HKCU\Console" /v VirtualTerminalLevel 2>nul | findstr "0x1" && echo:[99999;1H
)
:: Make ConEmu's environment variables available for child processes
:: if defined ConEmuBaseDir (
:: call :ifexist "%ConEmuBaseDir%\IsConEmu.cmd" >nul
if %ERRORLEVEL% == 0 call :ifexist "%ConEmuBaseDir%\ConEmuC.exe" /export
:: )
:: Colorize the command line prompt
:: if defined ConEmuBaseDir (
:: call :ifexist "%ConEmuBaseDir%\ColorPrompt.cmd"
:: )
goto :EOF
:: ========================================================================
:: EOF