Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
msys2_shell.cmd239 linesDownload Raw Back to Library
1@echo off
2setlocal EnableDelayedExpansion
3
4set "WD=%__CD__%"
5if NOT EXIST "%WD%msys-2.0.dll" set "WD=%~dp0usr\bin\"
6set "LOGINSHELL=bash"
7set /a msys2_shiftCounter=0
8
9rem To activate windows native symlinks uncomment next line
10rem set MSYS=winsymlinks:nativestrict
11
12rem Set debugging program for errors
13rem set MSYS=error_start:%WD%../../mingw64/bin/qtcreator.exe^|-debug^|^<process-id^>
14
15rem To export full current PATH from environment into MSYS2 use '-use-full-path' parameter
16rem or uncomment next line
17rem set MSYS2_PATH_TYPE=inherit
18
19:checkparams
20rem Help option
21if "x%~1" == "x-help" (
22  call :printhelp "%~nx0"
23  exit /b %ERRORLEVEL%
24)
25if "x%~1" == "x--help" (
26  call :printhelp "%~nx0"
27  exit /b %ERRORLEVEL%
28)
29if "x%~1" == "x-?" (
30  call :printhelp "%~nx0"
31  exit /b %ERRORLEVEL%
32)
33if "x%~1" == "x/?" (
34  call :printhelp "%~nx0"
35  exit /b %ERRORLEVEL%
36)
37rem Shell types
38if "x%~1" == "x-msys" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=MSYS& goto :checkparams
39if "x%~1" == "x-msys2" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=MSYS& goto :checkparams
40if "x%~1" == "x-mingw32" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=MINGW32& goto :checkparams
41if "x%~1" == "x-mingw64" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=MINGW64& goto :checkparams
42if "x%~1" == "x-ucrt64" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=UCRT64& goto :checkparams
43if "x%~1" == "x-clang64" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=CLANG64& goto :checkparams
44if "x%~1" == "x-clangarm64" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=CLANGARM64& goto :checkparams
45if "x%~1" == "x-mingw" shift& set /a msys2_shiftCounter+=1& (if exist "%WD%..\..\mingw64" (set MSYSTEM=MINGW64) else (set MSYSTEM=MINGW32))& goto :checkparams
46rem Console types
47if "x%~1" == "x-mintty" shift& set /a msys2_shiftCounter+=1& set MSYSCON=mintty.exe& goto :checkparams
48if "x%~1" == "x-conemu" shift& set /a msys2_shiftCounter+=1& set MSYSCON=conemu& goto :checkparams
49if "x%~1" == "x-defterm" shift& set /a msys2_shiftCounter+=1& set MSYSCON=defterm& goto :checkparams
50rem Other parameters
51if "x%~1" == "x-full-path" shift& set /a msys2_shiftCounter+=1& set MSYS2_PATH_TYPE=inherit& goto :checkparams
52if "x%~1" == "x-use-full-path" shift& set /a msys2_shiftCounter+=1& set MSYS2_PATH_TYPE=inherit& goto :checkparams
53if "x%~1" == "x-here" shift& set /a msys2_shiftCounter+=1& set CHERE_INVOKING=enabled_from_arguments& goto :checkparams
54if "x%~1" == "x-where" (
55  if "x%~2" == "x" (
56    echo Working directory is not specified for -where parameter. 1>&2
57    exit /b 2
58  )
59  cd /d "%~2" || (
60    echo Cannot set specified working diretory "%~2". 1>&2
61    exit /b 2
62  )
63  set CHERE_INVOKING=enabled_from_arguments
64
65  rem Ensure parentheses in argument do not interfere with FOR IN loop below.
66  set msys2_arg="%~2"
67  call :substituteparens msys2_arg
68  call :removequotes msys2_arg
69
70  rem Increment msys2_shiftCounter by number of words in argument (as cmd.exe saw it).
71  rem (Note that this form of FOR IN loop uses same delimiters as parameters.)
72  for %%a in (!msys2_arg!) do set /a msys2_shiftCounter+=1
73)& shift& shift& set /a msys2_shiftCounter+=1& goto :checkparams
74if "x%~1" == "x-no-start" shift& set /a msys2_shiftCounter+=1& set MSYS2_NOSTART=yes& goto :checkparams
75if "x%~1" == "x-shell" (
76  if "x%~2" == "x" (
77    echo Shell not specified for -shell parameter. 1>&2
78    exit /b 2
79  )
80  set LOGINSHELL="%~2"
81  call :removequotes LOGINSHELL
82  
83  set msys2_arg="%~2"
84  call :substituteparens msys2_arg
85  call :removequotes msys2_arg
86  for %%a in (!msys2_arg!) do set /a msys2_shiftCounter+=1
87)& shift& shift& set /a msys2_shiftCounter+=1& goto :checkparams
88
89rem Collect remaining command line arguments to be passed to shell
90if %msys2_shiftCounter% equ 0 set SHELL_ARGS=%* & goto cleanvars
91set msys2_full_cmd=%*
92for /f "tokens=%msys2_shiftCounter%,* delims=,;=	 " %%i in ("!msys2_full_cmd!") do set SHELL_ARGS=%%j
93
94:cleanvars
95set msys2_arg=
96set msys2_shiftCounter=
97set msys2_full_cmd=
98
99rem Setup proper title and icon
100if "%MSYSTEM%" == "MINGW32" (
101  set "CONTITLE=MinGW x32"
102  set "CONICON=mingw32.ico"
103) else if "%MSYSTEM%" == "MINGW64" (
104  set "CONTITLE=MinGW x64"
105  set "CONICON=mingw64.ico"
106) else if "%MSYSTEM%" == "UCRT64" (
107  set "CONTITLE=MinGW UCRT x64"
108  set "CONICON=ucrt64.ico"
109) else if "%MSYSTEM%" == "CLANG64" (
110  set "CONTITLE=MinGW Clang x64"
111  set "CONICON=clang64.ico"
112) else if "%MSYSTEM%" == "CLANGARM64" (
113  set "CONTITLE=MinGW Clang ARM64"
114  set "CONICON=clangarm64.ico"
115) else (
116  set "CONTITLE=MSYS2 MSYS"
117  set "CONICON=msys2.ico"
118)
119
120if "x%MSYSCON%" == "xmintty.exe" goto startmintty
121if "x%MSYSCON%" == "xconemu" goto startconemu
122if "x%MSYSCON%" == "xdefterm" goto startsh
123
124if NOT EXIST "%WD%mintty.exe" goto startsh
125set MSYSCON=mintty.exe
126:startmintty
127if not defined MSYS2_NOSTART (
128  start "%CONTITLE%" "%WD%mintty" -i "/%CONICON%" -t "%CONTITLE%" "/usr/bin/%LOGINSHELL%" -l !SHELL_ARGS!
129) else (
130  "%WD%mintty" -i "/%CONICON%" -t "%CONTITLE%" "/usr/bin/%LOGINSHELL%" -l !SHELL_ARGS!
131)
132exit /b %ERRORLEVEL%
133
134:startconemu
135call :conemudetect || (
136  echo ConEmu not found. Exiting. 1>&2
137  exit /b 1
138)
139if not defined MSYS2_NOSTART (
140  start "%CONTITLE%" "%ComEmuCommand%" /Here /Icon "%WD%..\..\%CONICON%" /cmd "%WD%\%LOGINSHELL%" -l !SHELL_ARGS!
141) else (
142  "%ComEmuCommand%" /Here /Icon "%WD%..\..\%CONICON%" /cmd "%WD%\%LOGINSHELL%" -l !SHELL_ARGS!
143)
144exit /b %ERRORLEVEL%
145
146:startsh
147set MSYSCON=
148if not defined MSYS2_NOSTART (
149  start "%CONTITLE%" "%WD%\%LOGINSHELL%" -l !SHELL_ARGS!
150) else (
151  "%WD%\%LOGINSHELL%" -l !SHELL_ARGS!
152)
153exit /b %ERRORLEVEL%
154
155:EOF
156exit /b 0
157
158:conemudetect
159set ComEmuCommand=
160if defined ConEmuDir (
161  if exist "%ConEmuDir%\ConEmu64.exe" (
162    set "ComEmuCommand=%ConEmuDir%\ConEmu64.exe"
163    set MSYSCON=conemu64.exe
164  ) else if exist "%ConEmuDir%\ConEmu.exe" (
165    set "ComEmuCommand=%ConEmuDir%\ConEmu.exe"
166    set MSYSCON=conemu.exe
167  )
168)
169if not defined ComEmuCommand (
170  ConEmu64.exe /Exit 2>nul && (
171    set ComEmuCommand=ConEmu64.exe
172    set MSYSCON=conemu64.exe
173  ) || (
174    ConEmu.exe /Exit 2>nul && (
175      set ComEmuCommand=ConEmu.exe
176      set MSYSCON=conemu.exe
177    )
178  )
179)
180if not defined ComEmuCommand (
181  FOR /F "tokens=*" %%A IN ('reg.exe QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ConEmu64.exe" /ve 2^>nul ^| find "REG_SZ"') DO (
182    set "ComEmuCommand=%%A"
183  )
184  if defined ComEmuCommand (
185    call set "ComEmuCommand=%%ComEmuCommand:*REG_SZ    =%%"
186    set MSYSCON=conemu64.exe
187  ) else (
188    FOR /F "tokens=*" %%A IN ('reg.exe QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ConEmu.exe" /ve 2^>nul ^| find "REG_SZ"') DO (
189      set "ComEmuCommand=%%A"
190    )
191    if defined ComEmuCommand (
192      call set "ComEmuCommand=%%ComEmuCommand:*REG_SZ    =%%"
193      set MSYSCON=conemu.exe
194    )
195  )
196)
197if not defined ComEmuCommand exit /b 2
198exit /b 0
199
200:printhelp
201echo Usage:
202echo     %~1 [options] [login shell parameters]
203echo.
204echo Options:
205echo     -mingw32 ^| -mingw64 ^| -ucrt64 ^| -clang64 ^|
206echo     -msys[2] ^| -clangarm64           Set shell type
207echo     -defterm ^| -mintty ^| -conemu     Set terminal type
208echo     -here                            Use current directory as working
209echo                                      directory
210echo     -where DIRECTORY                 Use specified DIRECTORY as working
211echo                                      directory
212echo     -[use-]full-path                 Use full current PATH variable
213echo                                      instead of trimming to minimal
214echo     -no-start                        Do not use "start" command and
215echo                                      return login shell resulting 
216echo                                      errorcode as this batch file 
217echo                                      resulting errorcode
218echo     -shell SHELL                     Set login shell
219echo     -help ^| --help ^| -? ^| /?         Display this help and exit
220echo.
221echo Any parameter that cannot be treated as valid option and all
222echo following parameters are passed as login shell command parameters.
223echo.
224exit /b 0
225
226:removequotes
227FOR /F "delims=" %%A IN ('echo %%%1%%') DO set %1=%%~A
228GOTO :eof
229
230:substituteparens
231SETLOCAL
232FOR /F "delims=" %%A IN ('echo %%%1%%') DO (
233    set value=%%A
234    set value=!value:^(=x!
235    set value=!value:^)=x!
236)
237ENDLOCAL & set %1=%value%
238GOTO :eof
239 
codekingpro/portable-devtools · Team Ai