@@ -4,6 +4,7 @@ REM This batch file forwards commands to a Unix-like shell
44
55REM We use the delayed-expansion feature of the command processor
66SETLOCAL EnableDelayedExpansion
7+ SETLOCAL EnableExtensions
78
89SET commands = %*
910
@@ -15,23 +16,36 @@ IF DEFINED WINEDEBUG (
1516 EXIT %ERRORLEVEL%
1617)
1718
19+ REM Is Cygwin already in the path?
20+ REM If not, look in a couple of likely locations for it
21+ WHERE /Q cygpath.exe 1 > NUL 2 > NUL
22+ IF %ERRORLEVEL% EQU 0 (
23+ SET cygwin_path = " "
24+ ) ELSE IF DEFINED CYGPATH (
25+ SET cygwin_path = %CYGPATH% \bin\
26+ ) ELSE IF EXIST C:\Cygwin64\bin (
27+ SET cygwin_path = C:\Cygwin64\bin\
28+ ) ELSE IF EXIST C:\Cygwin\bin (
29+ SET cygwin_path = C:\Cygwin\bin\
30+ ) ELSE (
31+ @ ECHO >& 2 Cannot locate a Cygwin installation
32+ EXIT 1
33+ )
1834
19- IF EXIST C:\Cygwin\bin (
20- REM We need to work around what looks to be a MCVS bug: the final parameter is
21- REM missing the terminating '"' in come circumstances
22- SET commands = %commands%
23-
24- @ echo Invoking Unix command '!commands! ' via Cygwin
25-
26- REM Obscure way to get the cmd.exe equivalent to `...` substitution
27- FOR /F " usebackq tokens=*" %%x IN (`C:\Cygwin\bin\cygpath.exe %CD% `) DO SET cygwin_cd = %%x
28- FOR /F " usebackq tokens=*" %%x IN (`C:\Cygwin\bin\cygpath.exe !commands! `) DO SET cygwin_cmd = !cygwin_cmd! %%x
35+ REM We need to work around what looks to be a MCVS bug: the final parameter is
36+ REM missing the terminating '"' in come circumstances
37+ SET commands = %commands%
2938
30- SET PATH = C:\Cygwin\bin:%PATH%
31- C:\Cygwin\bin\bash.exe -c 'cd !cygwin_cd! ^ &^ & !cygwin_cmd! '
32- EXIT %ERRORLEVEL%
39+ @ echo Invoking Unix command '!commands! ' via Cygwin
40+
41+ REM Obscure way to get the cmd.exe equivalent to `...` substitution
42+ FOR /F " usebackq tokens=*" %%x IN (`%cygwin_path% cygpath.exe %CD% `) DO SET cygwin_cd = %%x
43+ FOR %%x IN (!commands! ) DO (
44+ FOR /F " usebackq tokens=*" %%y IN (`%cygwin_path% bash.exe -c 'if [[ \'%%x \' ^ =^ = -* ]] ^ ; then echo \'%%x \' ^ ; else cygpath \'%%x \' ^ ; fi'`) DO SET cygwin_cmd = !cygwin_cmd! %%y
3345)
3446
35- @ echo Could not find Cygwin or wine
36- EXIT 1
47+ REM All the parameters have been Unix-ified; run the command
48+ SET PATH = %cygwin_path% :%PATH%
49+ %cygwin_path% bash.exe -c 'cd !cygwin_cd! ^ &^ & !cygwin_cmd! '
50+ EXIT %ERRORLEVEL%
3751
0 commit comments