mirror of
https://github.com/cmderdev/cmder.git
synced 2025-02-25 23:00:23 +08:00
Merge pull request #1758 from xiazeyu/master
lib to check init.bat's custom args
This commit is contained in:
commit
66da1716bc
52
README.md
52
README.md
@ -44,7 +44,7 @@ The Cmder's user interface is also designed to be more eye pleasing, and you can
|
|||||||
| Argument | Description |
|
| Argument | Description |
|
||||||
| ------------------- | ----------------------------------------------------------------------- |
|
| ------------------- | ----------------------------------------------------------------------- |
|
||||||
| `/C [user_root_path]` | Individual user Cmder root folder. Example: `%userprofile%\cmder_config` |
|
| `/C [user_root_path]` | Individual user Cmder root folder. Example: `%userprofile%\cmder_config` |
|
||||||
| `/SINGLE` | Start Cmder is single mode. |
|
| `/SINGLE` | Start Cmder in single mode. |
|
||||||
| `/START [start_path]` | Folder path to start in. |
|
| `/START [start_path]` | Folder path to start in. |
|
||||||
| `/TASK [task_name]` | Task to start after launch. |
|
| `/TASK [task_name]` | Task to start after launch. |
|
||||||
|
|
||||||
@ -148,6 +148,7 @@ You may find some Monokai color schemes for mintty to match Cmder [here](https:/
|
|||||||
| `/svn_ssh [path to ssh.exe]` | Define `%SVN_SSH%` so we can use git svn with ssh svn repositories. | `%GIT_INSTALL_ROOT%\bin\ssh.exe` |
|
| `/svn_ssh [path to ssh.exe]` | Define `%SVN_SSH%` so we can use git svn with ssh svn repositories. | `%GIT_INSTALL_ROOT%\bin\ssh.exe` |
|
||||||
| `/user_aliases [file path]` | File path pointing to user aliases. | `%CMDER_ROOT%\config\user-liases.cmd` |
|
| `/user_aliases [file path]` | File path pointing to user aliases. | `%CMDER_ROOT%\config\user-liases.cmd` |
|
||||||
| `/v` | Enables verbose output. | not set |
|
| `/v` | Enables verbose output. | not set |
|
||||||
|
| (custom arguments) | User defined arguments processed by `cexec`. Type `cexec /?` for more useage. | not set |
|
||||||
|
|
||||||
### Cmder Shell User Config
|
### Cmder Shell User Config
|
||||||
Single user portable configuration is possible using the cmder specific shell config files. Edit the below files to add your own configuration:
|
Single user portable configuration is possible using the cmder specific shell config files. Edit the below files to add your own configuration:
|
||||||
@ -246,7 +247,56 @@ Uncomment and edit the below line in the script to use Cmder config even when la
|
|||||||
# CMDER_ROOT=${USERPROFILE}/cmder # This is not required if launched from Cmder.
|
# CMDER_ROOT=${USERPROFILE}/cmder # This is not required if launched from Cmder.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Customizing user sessions using `init.bat` custom arguments.
|
||||||
|
|
||||||
|
You can pass custom arguments to `init.bat` and use `cexec.cmd` in your `user_profile.cmd` to evaluate these
|
||||||
|
arguments then execute commands based on a particular flag being detected or not.
|
||||||
|
|
||||||
|
`init.bat` creates two shortcuts for using `cexec.cmd` in your profile scripts.
|
||||||
|
|
||||||
|
#### `%ccall%` - Evaluates flags, runs commands if found, and returns to the calling script and continues.
|
||||||
|
|
||||||
|
```
|
||||||
|
ccall=call C:\Users\user\cmderdev\vendor\bin\cexec.cmd
|
||||||
|
```
|
||||||
|
|
||||||
|
Example: `%ccall% /startnotepad start notepad.exe`
|
||||||
|
|
||||||
|
#### `%cexec%` - Evaluates flags, runs commands if found, and does not return to the calling script.
|
||||||
|
|
||||||
|
```
|
||||||
|
cexec=C:\Users\user\cmderdev\vendor\bin\cexec.cmd
|
||||||
|
```
|
||||||
|
|
||||||
|
Example: `%cexec% /startnotepad start notepad.exe`
|
||||||
|
|
||||||
|
It is useful when you have multiple tasks to execute `cmder` and need it to initialize
|
||||||
|
the session differently depending on the task chosen.
|
||||||
|
|
||||||
|
To conditionally start `notepad.exe` when you start a specific `cmder` task:
|
||||||
|
|
||||||
|
* Press <kbd>win</kbd>+<kbd>alt</kbd>+<kbd>t</kbd>
|
||||||
|
* Click `+` to add a new task.
|
||||||
|
* Add the below to the `Commands` block:
|
||||||
|
|
||||||
|
```batch
|
||||||
|
|
||||||
|
cmd.exe /k ""%ConEmuDir%\..\init.bat" /startnotepad"
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
* Add the below to your `%cmder_root%\config\user_profile.cmd`
|
||||||
|
|
||||||
|
```batch
|
||||||
|
|
||||||
|
%ccall% "/startNotepad" "start" "notepad.exe"`
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
To see detailed usage of `cexec`, type `cexec /?` in cmder.
|
||||||
|
|
||||||
### Integrating Cmder with [Hyper](https://github.com/zeit/hyper), [Microsoft VS Code](https://code.visualstudio.com/), and your favorite IDEs
|
### Integrating Cmder with [Hyper](https://github.com/zeit/hyper), [Microsoft VS Code](https://code.visualstudio.com/), and your favorite IDEs
|
||||||
|
|
||||||
Cmder by default comes with a vendored ConEmu installation as the underlying terminal emulator, as stated [here](https://conemu.github.io/en/cmder.html).
|
Cmder by default comes with a vendored ConEmu installation as the underlying terminal emulator, as stated [here](https://conemu.github.io/en/cmder.html).
|
||||||
|
|
||||||
However, Cmder can in fact run in a variety of other terminal emulators, and even integrated IDEs. Assuming you have the latest version of Cmder, follow the following instructions to get Cmder working with your own terminal emulator.
|
However, Cmder can in fact run in a variety of other terminal emulators, and even integrated IDEs. Assuming you have the latest version of Cmder, follow the following instructions to get Cmder working with your own terminal emulator.
|
||||||
|
135
vendor/bin/cexec.cmd
vendored
Normal file
135
vendor/bin/cexec.cmd
vendored
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal
|
||||||
|
|
||||||
|
if "%~1" equ "" goto :wrongSyntax
|
||||||
|
|
||||||
|
if not defined CMDER_USER_FLAGS (
|
||||||
|
:: in case nothing was passed to %CMDER_USER_FLAGS%
|
||||||
|
set "CMDER_USER_FLAGS= "
|
||||||
|
)
|
||||||
|
|
||||||
|
set "feNot=false"
|
||||||
|
goto :parseArgument
|
||||||
|
|
||||||
|
:doShift
|
||||||
|
shift
|
||||||
|
|
||||||
|
:parseArgument
|
||||||
|
set "currenArgu=%~1"
|
||||||
|
if /i "%currenArgu%" equ "/setPath" (
|
||||||
|
:: set %flag_exists% shortcut
|
||||||
|
endlocal
|
||||||
|
set "ccall=call %~dp0cexec.cmd"
|
||||||
|
set "cexec=%~dp0cexec.cmd"
|
||||||
|
) else if /i "%currenArgu%" == "/?" (
|
||||||
|
goto :help
|
||||||
|
) else if /i "%currenArgu%" equ "/help" (
|
||||||
|
goto :help
|
||||||
|
) else if /i "%currenArgu%" equ "/h" (
|
||||||
|
goto :help
|
||||||
|
) else if /i "%currenArgu%" equ "NOT" (
|
||||||
|
set "feNot=true"
|
||||||
|
goto :doShift
|
||||||
|
) else (
|
||||||
|
if "%~1" equ "" goto :wrongSyntax
|
||||||
|
if "%~2" equ "" goto :wrongSyntax
|
||||||
|
set "feFlagName=%~1"
|
||||||
|
set "feCommand=%~2"
|
||||||
|
if not "%~3" equ "" (
|
||||||
|
set "feParam=%~3"
|
||||||
|
)
|
||||||
|
goto :detect
|
||||||
|
)
|
||||||
|
|
||||||
|
:detect
|
||||||
|
:: 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% "
|
||||||
|
:: echo.
|
||||||
|
:: echo %CMDER_USER_FLAGS%
|
||||||
|
:: echo %feNOT%
|
||||||
|
:: echo %feFlagName%
|
||||||
|
:: echo %feCommand%
|
||||||
|
:: echo %feParam%
|
||||||
|
:: echo.
|
||||||
|
echo %CMDER_USER_FLAGS% | find /i "%feFlagName%">nul
|
||||||
|
if "%ERRORLEVEL%" == "0" (
|
||||||
|
if "%feNOT%" == "false" (
|
||||||
|
endlocal && call %feCommand% %feParam%
|
||||||
|
exit /b 0
|
||||||
|
)
|
||||||
|
) else (
|
||||||
|
if "%feNOT%" == "true" (
|
||||||
|
endlocal && call %feCommand% %feParam%
|
||||||
|
exit /b 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
endlocal
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:wrongSyntax
|
||||||
|
echo The syntax of the command is incorrect.
|
||||||
|
echo.
|
||||||
|
echo use /? for help
|
||||||
|
echo.
|
||||||
|
endlocal
|
||||||
|
exit /b
|
||||||
|
|
||||||
|
:help
|
||||||
|
echo.
|
||||||
|
echo CExec - Conditional Exec
|
||||||
|
echo.
|
||||||
|
echo Handles with custom arguments for cmder's init.bat.
|
||||||
|
echo written by xiazeyu, inspired DRSDavidSoft.
|
||||||
|
echo.
|
||||||
|
echo Usage:
|
||||||
|
echo.
|
||||||
|
echo cexec /setPath [NOT] flagName command/program [parameters]
|
||||||
|
echo.
|
||||||
|
echo /setPath Generate a global varibles %%ccall%% and %%cexec%% for
|
||||||
|
echo quicker use. Following arguments will be ignored.
|
||||||
|
echo.
|
||||||
|
echo NOT Specifies that cexec should carry out
|
||||||
|
echo the command only if the flag is missing.
|
||||||
|
echo.
|
||||||
|
echo /[flagName] Specifies which flag name is to detect. It's recommand
|
||||||
|
echo to use a pair of double quotation marks to wrap
|
||||||
|
echo your flag name to avoid exceed expectation.
|
||||||
|
echo.
|
||||||
|
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.
|
||||||
|
echo.
|
||||||
|
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.
|
||||||
|
echo.
|
||||||
|
echo Examples:
|
||||||
|
echo.
|
||||||
|
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.
|
||||||
|
echo.
|
||||||
|
echo Case 1:
|
||||||
|
echo.
|
||||||
|
echo The following command in `user_profile.cmd` would execute "notepad.exe" and continue running the `user_profile.cmd`
|
||||||
|
echo.
|
||||||
|
echo "%ccall%" "/startNotepad" "start" "notepad.exe"
|
||||||
|
echo.
|
||||||
|
echo If you pass parameter to init.bat like:
|
||||||
|
echo.
|
||||||
|
echo init.bat /startNotepad
|
||||||
|
echo.
|
||||||
|
echo Case 2:
|
||||||
|
echo.
|
||||||
|
echo The following command in `user_profile.cmd` would execute "notepad.exe" and stop running the `user_profile.cmd`
|
||||||
|
echo.
|
||||||
|
echo "%cexec%" NOT "/dontStartNotepad" "start" "notepad.exe"
|
||||||
|
echo.
|
||||||
|
echo UNLESS you pass parameter to init.bat like:
|
||||||
|
echo.
|
||||||
|
echo init.bat /dontStartNotepad
|
||||||
|
echo.
|
||||||
|
endlocal
|
||||||
|
exit /b
|
9
vendor/init.bat
vendored
9
vendor/init.bat
vendored
@ -10,6 +10,7 @@
|
|||||||
set verbose_output=0
|
set verbose_output=0
|
||||||
set debug_output=0
|
set debug_output=0
|
||||||
set max_depth=1
|
set max_depth=1
|
||||||
|
set "CMDER_USER_FLAGS= "
|
||||||
|
|
||||||
:: Find root dir
|
:: Find root dir
|
||||||
if not defined CMDER_ROOT (
|
if not defined CMDER_ROOT (
|
||||||
@ -27,6 +28,7 @@ if not defined CMDER_ROOT (
|
|||||||
:: Remove trailing '\' from %CMDER_ROOT%
|
:: Remove trailing '\' from %CMDER_ROOT%
|
||||||
if "%CMDER_ROOT:~-1%" == "\" SET "CMDER_ROOT=%CMDER_ROOT:~0,-1%"
|
if "%CMDER_ROOT:~-1%" == "\" SET "CMDER_ROOT=%CMDER_ROOT:~0,-1%"
|
||||||
|
|
||||||
|
call "%cmder_root%\vendor\bin\cexec.cmd" /setpath
|
||||||
call "%cmder_root%\vendor\lib\lib_base"
|
call "%cmder_root%\vendor\lib\lib_base"
|
||||||
call "%cmder_root%\vendor\lib\lib_path"
|
call "%cmder_root%\vendor\lib\lib_path"
|
||||||
call "%cmder_root%\vendor\lib\lib_console"
|
call "%cmder_root%\vendor\lib\lib_console"
|
||||||
@ -80,6 +82,8 @@ call "%cmder_root%\vendor\lib\lib_profile"
|
|||||||
) else if /i "%1" == "/svn_ssh" (
|
) else if /i "%1" == "/svn_ssh" (
|
||||||
set SVN_SSH=%2
|
set SVN_SSH=%2
|
||||||
shift
|
shift
|
||||||
|
) else (
|
||||||
|
set "CMDER_USER_FLAGS=%1 %CMDER_USER_FLAGS%"
|
||||||
)
|
)
|
||||||
shift
|
shift
|
||||||
goto var_loop
|
goto var_loop
|
||||||
@ -348,6 +352,11 @@ echo.
|
|||||||
echo :: you can add your plugins to the cmder path like so
|
echo :: you can add your plugins to the cmder path like so
|
||||||
echo :: set "PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%%"
|
echo :: set "PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%%"
|
||||||
echo.
|
echo.
|
||||||
|
echo :: arguments in this batch are passed from init.bat, you can quickly parse them like so:
|
||||||
|
echo :: more useage can be seen by typing "cexec /?"
|
||||||
|
echo.
|
||||||
|
echo :: %%ccall%% "/customOption" "command/program"
|
||||||
|
echo.
|
||||||
echo @echo off
|
echo @echo off
|
||||||
) >"%initialConfig%"
|
) >"%initialConfig%"
|
||||||
)
|
)
|
||||||
|
1
vendor/lib/lib_profile.cmd
vendored
1
vendor/lib/lib_profile.cmd
vendored
@ -44,3 +44,4 @@ exit /b
|
|||||||
)
|
)
|
||||||
popd
|
popd
|
||||||
exit /b
|
exit /b
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user