-
Notifications
You must be signed in to change notification settings - Fork 10
/
bc.bat
153 lines (128 loc) · 6.02 KB
/
bc.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
153
@setlocal EnableDelayedExpansion
@echo off
:init
set __batname=%~nx0
set __batfile=%~0
set __app=Beyond Compare
set __quiet=
set /a __wait=1
set __bc=
set cmds=
set showname=
:parse
if "%~1"=="" goto :main
if "%~1"=="/?" call :usage && endlocal && exit /B 0
if /i "%~1"=="--help" call :usage && endlocal && exit /B 0
if /i "%~1"=="-help" call :usage && endlocal && exit /B 0
if /i "%~1"=="--online" call :usage online && endlocal && exit /B 0
if /i "%~1"=="-online" call :usage online && endlocal && exit /B 0
if /i "%~1"=="--online-help" call :usage online && endlocal && exit /B 0
if /i "%~1"=="--quiet" set __quiet=true && shift && goto :parse
if /i "%~1"=="-quiet" set __quiet=true && shift && goto :parse
if /i "%~1"=="-" set /a __wait=0 && shift && goto :parse
if /i "%~1"=="--" set /a __wait=0 && shift && goto :parse
set arg=%~1
rem echo !arg:~0,1!
rem :: If the argument contains '~/' then replace it with %UserProfile%
rem if "!arg:~0,2!"=="~\" (
rem set arg=!arg:~/=%UserProfile%!
rem echo arg=!arg!
rem )
:: My common shorcut/replacements..
if "!arg:~0,2!"=="//" (
set arg=%UserProfile%\!arg:~2!
set showname=true
)
if "!arg:~0,3!"=="/b/" (
set arg=%BIN%\!arg:~3!
set showname=true
)
if "!arg:~0,3!"=="/w/" (
set arg=%UserProfile%\Desktop\!arg:~3!
set showname=true
)
if "!arg:~0,3!"=="/e/" (
set arg=%UserProfile%\Desktop\!arg:~3!
set showname=true
)
if "!arg:~0,3!"=="/d/" (
set arg=%UserProfile%\Documents\!arg:~3!
set showname=true
)
:: If the argument doesn't start with a '/' or '-' then
:: replace all '/' characters with '\'..
if not "!arg:~0,1!"=="/" (
if not "!arg:~0,1!"=="-" (
:: Replace dlb-backslashes with a single back-slash
set arg=!arg:\\=\!
:: Replace forward-slashes with back-slashes
set arg=!arg:/=\!
set showname=true
)
)
set cmds=%cmds% %arg%
shift
goto :parse
:main
rem call :findbc
rem set __bc=%bin%\apps\Beyond Compare 3\BCompare.exe
set __bc=%bin%\apps\Beyond Compare 4\BCompare.exe
rem echo __bc==%__bc%
if exist "%__bc%" (
if not defined __quiet echo Opening %__app%..
rem if %__wait% EQU 0 start "beyond compare" "%__app%" /b "%__bc%" %*
rem if %__wait% NEQ 0 call "%__app%" /b "%__bc%" %*
rem left-trim the input
for /f "tokens=* delims= " %%a in ("!cmds!") do set cmds=%%a
if defined showname echo "%__bc%" %cmds% && set "showname="
start "%__app%" /b "%__bc%" %cmds%
endlocal && set "__bc=%__bc%" && exit /B %errorlevel%
)
echo Could not find %__app%
endlocal && set "__bc=" && exit /B 0
:usage
echo %__batname% ^| Created 2010-2013 @wasatchwizard
echo ^| Executes Beyond Compare, trying numerous install locations.
echo ^| Tries to find v4, then v3, but will resort to v2 if necessary.
echo.
echo USAGE:
echo %__batname% [options] file1 file2
echo %__batname% [options] path1 path2
echo.
echo All arguments are passed to Beyond Compare as is.
echo.
if /i "%~1"=="online" (
echo Opening online help..
start "BCOnlineHelp" "http://www.scootersoftware.com/help/index.html?command_line_reference.html"
) else (
echo For online help for Beyond Compare type `%__batname% --online-help`,
echo which will open: http://www.scootersoftware.com/help/index.html?command_line_reference.html
)
goto :eof
rem :findbc
rem rem Try to find v4 first..
rem if exist "%bin%\apps\Beyond Compare 4\BCompare.exe" set "__bc=%BIN%\apps\Beyond Compare 4\BCompare.exe" && goto :eof
rem if exist "C:\bin\apps\Beyond Compare 4\BCompare.exe" set "__bc=C:\bin\apps\Beyond Compare 4\BCompare.exe" && goto :eof
rem if exist "%Profile%\Root\apps\Beyond Compare 4\BCompare.exe" set "__bc=%Profile%\Root\apps\Beyond Compare 4\BCompare.exe" && goto :eof
rem if exist "T:\bin\apps\Beyond Compare 4\BCompare.exe" set "__bc=T:\root\apps\Beyond Compare 4\BCompare.exe" && goto :eof
rem if exist "C:\Program Files (x86)\Beyond Compare 4\BCompare.exe" set "__bc=c:\Program Files (x86)\Beyond Compare 4\BCompare.exe" && goto :eof
rem if exist "C:\Program Files\Beyond Compare 4\BCompare.exe" set "__bc=C:\Program Files\Beyond Compare 4\BCompare.exe" && goto :eof
rem
rem rem Try to find v3..
rem if exist "%bin%\apps\Beyond Compare 3\BCompare.exe" set "__bc=%BIN%\apps\Beyond Compare 3\BCompare.exe" && goto :eof
rem if exist "C:\bin\apps\Beyond Compare 3\BCompare.exe" set "__bc=C:\bin\apps\Beyond Compare 3\BCompare.exe" && goto :eof
rem if exist "%Profile%\Root\apps\Beyond Compare 3\BCompare.exe" set "__bc=%Profile%\Root\apps\Beyond Compare 3\BCompare.exe" && goto :eof
rem if exist "T:\bin\apps\Beyond Compare 3\BCompare.exe" set "__bc=T:\root\apps\Beyond Compare 3\BCompare.exe" && goto :eof
rem if exist "C:\Program Files (x86)\Beyond Compare 3\BCompare.exe" set "__bc=c:\Program Files (x86)\Beyond Compare 3\BCompare.exe" && goto :eof
rem if exist "C:\Program Files\Beyond Compare 3\BCompare.exe" set "__bc=C:\Program Files\Beyond Compare 3\BCompare.exe" && goto :eof
rem
rem rem May as well try v2..
rem if exist "%bin%\apps\Beyond Compare 2\BC2.exe" set "__bc=%BIN%\apps\Beyond Compare 2\BC2.exe" && goto :eof
rem if exist "C:\bin\apps\Beyond Compare 2\BC2.exe" set "__bc=C:\bin\apps\Beyond Compare 2\BC2.exe" && goto :eof
rem if exist "C:\root\apps\Beyond Compare 2\BC2.exe" set "__bc=C:\root\apps\Beyond Compare 2\BC2.exe" && goto :eof
rem if exist "%Profile%\Root\apps\Beyond Compare 2\BC2.exe" set "__bc=%Profile%\Root\Apps\Beyond Compare 2\BC2.exe" && goto :eof
rem if exist "T:\bin\apps\Beyond Compare 3\BCompare.exe" set "__bc=T:\root\apps\Beyond Compare 3\BCompare.exe" && goto :eof
rem if exist "C:\Program Files (x86)\Beyond Compare 2\BC2.exe" set "__bc=C:\Program Files (x86)\Beyond Compare 2\BC2.exe" && goto :eof
rem
rem set "__bc="
rem goto :eof