2018-05-18 20:32:05 +08:00
|
|
|
@echo off
|
|
|
|
setlocal
|
|
|
|
|
|
|
|
if "%~1" equ "" goto :wrongSyntax
|
|
|
|
|
|
|
|
if not defined CMDER_USER_FLAGS (
|
2018-08-06 13:09:59 +08:00
|
|
|
:: in case nothing was passed to %CMDER_USER_FLAGS%
|
2018-05-18 21:02:36 +08:00
|
|
|
set "CMDER_USER_FLAGS= "
|
2018-05-18 20:32:05 +08:00
|
|
|
)
|
|
|
|
|
2018-08-06 13:09:59 +08:00
|
|
|
set "feNot=false"
|
2018-05-18 20:32:05 +08:00
|
|
|
goto :parseArgument
|
|
|
|
|
|
|
|
:doShift
|
|
|
|
shift
|
|
|
|
|
|
|
|
:parseArgument
|
2018-08-06 13:09:59 +08:00
|
|
|
set "currenArgu=%~1"
|
|
|
|
if /i "%currenArgu%" equ "/setPath" (
|
|
|
|
:: set %flag_exists% shortcut
|
|
|
|
endlocal
|
2018-09-16 02:55:54 +08:00
|
|
|
set "ccall=call %~dp0cexec.cmd"
|
|
|
|
set "cexec=%~dp0cexec.cmd"
|
2018-08-06 13:09:59 +08:00
|
|
|
) else if /i "%currenArgu%" == "/?" (
|
2018-09-16 02:55:54 +08:00
|
|
|
call :help
|
2018-08-06 13:09:59 +08:00
|
|
|
) else if /i "%currenArgu%" equ "/help" (
|
2018-05-18 20:32:05 +08:00
|
|
|
goto :help
|
2018-08-06 13:09:59 +08:00
|
|
|
) else if /i "%currenArgu%" equ "/h" (
|
2018-05-18 20:32:05 +08:00
|
|
|
goto :help
|
2018-08-06 13:09:59 +08:00
|
|
|
) else if /i "%currenArgu%" equ "NOT" (
|
|
|
|
set "feNot=true"
|
2018-05-18 20:32:05 +08:00
|
|
|
goto :doShift
|
|
|
|
) else (
|
|
|
|
if "%~1" equ "" goto :wrongSyntax
|
|
|
|
if "%~2" equ "" goto :wrongSyntax
|
2018-08-06 13:09:59 +08:00
|
|
|
set "feFlagName=%~1"
|
2018-05-27 10:22:44 +08:00
|
|
|
set "feCommand=%~2"
|
2018-08-06 13:09:59 +08:00
|
|
|
if not "%~3" equ "" (
|
|
|
|
set "feParam=%~3"
|
|
|
|
)
|
2018-05-18 20:32:05 +08:00
|
|
|
goto :detect
|
|
|
|
)
|
|
|
|
|
|
|
|
:detect
|
2018-08-06 13:09:59 +08:00
|
|
|
:: to avoid erroneous deteciton like "/do" "/doNOT", which both have a "/do"
|
|
|
|
:: we added a space after the flag name, like "/do ", which won't match "/doN"
|
|
|
|
set "feFlagName=%feFlagName% "
|
2018-05-18 20:32:05 +08:00
|
|
|
:: echo.
|
|
|
|
:: echo %CMDER_USER_FLAGS%
|
2018-05-27 10:22:44 +08:00
|
|
|
:: echo %feNOT%
|
2018-08-06 13:09:59 +08:00
|
|
|
:: echo %feFlagName%
|
2018-05-27 10:22:44 +08:00
|
|
|
:: echo %feCommand%
|
2018-08-06 13:09:59 +08:00
|
|
|
:: echo %feParam%
|
2018-05-18 20:32:05 +08:00
|
|
|
:: echo.
|
2018-08-06 13:09:59 +08:00
|
|
|
echo %CMDER_USER_FLAGS% | find /i "%feFlagName%">nul
|
2018-05-18 20:32:05 +08:00
|
|
|
if "%ERRORLEVEL%" == "0" (
|
2018-05-27 10:22:44 +08:00
|
|
|
if "%feNOT%" == "false" (
|
2018-08-06 13:09:59 +08:00
|
|
|
call %feCommand% %feParam%
|
2018-09-16 02:55:54 +08:00
|
|
|
exit /b 0
|
2018-05-18 20:32:05 +08:00
|
|
|
)
|
|
|
|
) else (
|
2018-05-27 10:22:44 +08:00
|
|
|
if "%feNOT%" == "true" (
|
2018-08-06 13:09:59 +08:00
|
|
|
call %feCommand% %feParam%
|
2018-09-16 02:55:54 +08:00
|
|
|
exit /b 0
|
2018-05-18 20:32:05 +08:00
|
|
|
)
|
|
|
|
)
|
2018-08-06 13:09:59 +08:00
|
|
|
endlocal
|
2018-09-16 02:55:54 +08:00
|
|
|
exit /b 1
|
2018-05-18 20:32:05 +08:00
|
|
|
|
|
|
|
:wrongSyntax
|
|
|
|
echo The syntax of the command is incorrect.
|
|
|
|
echo.
|
|
|
|
echo use /? for help
|
|
|
|
echo.
|
2018-08-06 13:09:59 +08:00
|
|
|
endlocal
|
2018-05-18 20:32:05 +08:00
|
|
|
exit /b
|
|
|
|
|
|
|
|
:help
|
2018-05-27 10:22:44 +08:00
|
|
|
echo.
|
2018-09-16 02:55:54 +08:00
|
|
|
echo CExec - Conditional Exec
|
2018-05-27 10:22:44 +08:00
|
|
|
echo.
|
|
|
|
echo Handles with custom arguments for cmder's init.bat.
|
|
|
|
echo written by xiazeyu, inspired DRSDavidSoft.
|
2018-05-18 20:32:05 +08:00
|
|
|
echo.
|
|
|
|
echo Usage:
|
|
|
|
echo.
|
2018-09-16 02:55:54 +08:00
|
|
|
echo cexec [NOT] flagName command/program [parameters]
|
2018-08-06 13:09:59 +08:00
|
|
|
echo.
|
2018-09-16 02:55:54 +08:00
|
|
|
echo /setPath Generate a global varible %%cexec%% for
|
2018-08-06 13:09:59 +08:00
|
|
|
echo quicker use. Following arguments will be ignored.
|
|
|
|
echo.
|
2018-09-16 02:55:54 +08:00
|
|
|
echo NOT Specifies that cexec should carry out
|
2018-08-06 13:09:59 +08:00
|
|
|
echo the command only if the flag is missing.
|
2018-05-18 20:32:05 +08:00
|
|
|
echo.
|
2018-09-16 02:55:54 +08:00
|
|
|
echo /[flagName] Specifies which flag name is to detect. It's recommand
|
2018-08-06 13:09:59 +08:00
|
|
|
echo to use a pair of double quotation marks to wrap
|
|
|
|
echo your flag name to avoid exceed expectation.
|
2018-05-18 20:32:05 +08:00
|
|
|
echo.
|
2018-08-06 13:09:59 +08:00
|
|
|
echo command/program Specifies the command to carry out if the
|
|
|
|
echo argument name is detected. It's recommand to
|
|
|
|
echo use a pair of double quotation marks to
|
|
|
|
echo wrap your command to avoid exceed expectation.
|
2018-05-18 20:32:05 +08:00
|
|
|
echo.
|
2018-08-06 13:09:59 +08:00
|
|
|
echo parameters These are the parameters passed to the command/program.
|
|
|
|
echo It's recommand to use a pair of double quotation marks
|
|
|
|
echo to wrap your flag name to avoid exceed expectation.
|
2018-05-18 20:32:05 +08:00
|
|
|
echo.
|
|
|
|
echo Examples:
|
|
|
|
echo.
|
2018-09-16 02:55:54 +08:00
|
|
|
echo These examples are expected to be written in %cmder_root%/config/user-profile.cmd
|
|
|
|
echo CExec evaluates the environment varible "CMDER_USER_FLAGS" and conditionally
|
|
|
|
echo caries out actions based on flags that are passed.
|
2018-05-18 20:32:05 +08:00
|
|
|
echo.
|
|
|
|
echo Case 1:
|
|
|
|
echo.
|
|
|
|
echo The following command in user-profile.cmd would execute "notepad.exe"
|
|
|
|
echo.
|
2018-09-16 02:55:54 +08:00
|
|
|
echo call cexec "/startNotepad" "start" "notepad.exe"
|
2018-05-18 20:32:05 +08:00
|
|
|
echo.
|
2018-09-16 02:55:54 +08:00
|
|
|
echo If you pass parameter to init.bat like:
|
2018-05-18 20:32:05 +08:00
|
|
|
echo.
|
|
|
|
echo init.bat /startNotepad
|
|
|
|
echo.
|
|
|
|
echo Case 2:
|
|
|
|
echo.
|
|
|
|
echo The following command in user-profile.cmd would execute "notepad.exe"
|
|
|
|
echo.
|
2018-09-16 02:55:54 +08:00
|
|
|
echo call cexec NOT "/dontStartNotepad" "start" "notepad.exe"
|
2018-05-18 20:32:05 +08:00
|
|
|
echo.
|
|
|
|
echo UNLESS you pass parameter to init.bat like:
|
|
|
|
echo.
|
|
|
|
echo init.bat /dontStartNotepad
|
|
|
|
echo.
|
2018-08-06 13:09:59 +08:00
|
|
|
endlocal
|
2018-05-18 20:32:05 +08:00
|
|
|
exit /b
|