From a06d4e93ec3f033646c9b4f559ba6b3ef96fd7db Mon Sep 17 00:00:00 2001 From: xiazeyu_2011 Date: Mon, 30 Apr 2018 20:31:01 +0800 Subject: [PATCH 01/23] Pass arguments to user-profile.cmd --- vendor/init.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index 380100a..6783116 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -290,14 +290,14 @@ if not defined HOME set "HOME=%USERPROFILE%" set "initialConfig=%CMDER_ROOT%\config\user-profile.cmd" if exist "%CMDER_ROOT%\config\user-profile.cmd" ( REM Create this file and place your own command in there - call "%CMDER_ROOT%\config\user-profile.cmd" + call "%CMDER_ROOT%\config\user-profile.cmd" %* ) if defined CMDER_USER_CONFIG ( set "initialConfig=%CMDER_USER_CONFIG%\user-profile.cmd" if exist "%CMDER_USER_CONFIG%\user-profile.cmd" ( REM Create this file and place your own command in there - call "%CMDER_USER_CONFIG%\user-profile.cmd" + call "%CMDER_USER_CONFIG%\user-profile.cmd" %* ) ) From 99f51b0fc0ffa0195d3d0f11903834f56a241bf1 Mon Sep 17 00:00:00 2001 From: xiazeyu_2011 Date: Tue, 1 May 2018 13:02:21 +0800 Subject: [PATCH 02/23] fix conflict with init.bat build-in command parser, update user-profile.cmd --- vendor/init.bat | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index 6783116..e68b331 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -81,6 +81,7 @@ call "%cmder_root%\vendor\lib\lib_profile" set SVN_SSH=%2 shift ) + set "CMDER_FLAGS=%CMDER_FLAGS% %1" shift goto var_loop @@ -290,14 +291,14 @@ if not defined HOME set "HOME=%USERPROFILE%" set "initialConfig=%CMDER_ROOT%\config\user-profile.cmd" if exist "%CMDER_ROOT%\config\user-profile.cmd" ( REM Create this file and place your own command in there - call "%CMDER_ROOT%\config\user-profile.cmd" %* + call "%CMDER_ROOT%\config\user-profile.cmd" %CMDER_FLAGS% ) if defined CMDER_USER_CONFIG ( set "initialConfig=%CMDER_USER_CONFIG%\user-profile.cmd" if exist "%CMDER_USER_CONFIG%\user-profile.cmd" ( REM Create this file and place your own command in there - call "%CMDER_USER_CONFIG%\user-profile.cmd" %* + call "%CMDER_USER_CONFIG%\user-profile.cmd" %CMDER_FLAGS% ) ) @@ -317,6 +318,12 @@ echo. echo :: you can add your plugins to the cmder path like so echo :: set "PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%%" echo. +echo :: pass your custom arguments to init.bat, and you can parse them like so +echo :: echo %* | find /i "/noautorun">nul +echo :: if "%ERRORLEVEL%" == "1" ( +echo :: call vsCode +echo :: ) +echo. echo @echo off ) >"%initialConfig%" ) From 9a3a8f23d077cf591ff13d9de651197eae305466 Mon Sep 17 00:00:00 2001 From: Dax T Games Date: Tue, 1 May 2018 08:57:02 -0400 Subject: [PATCH 03/23] Little Changes --- vendor/init.bat | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index e68b331..7379dae 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -10,6 +10,7 @@ set verbose-output=0 set debug-output=0 set max_depth=1 +set "CMDER_FLAGS=" :: Find root dir if not defined CMDER_ROOT ( @@ -80,8 +81,9 @@ call "%cmder_root%\vendor\lib\lib_profile" ) else if /i "%1" == "/svn_ssh" ( set SVN_SSH=%2 shift + ) else ( + set "CMDER_FLAGS=%CMDER_FLAGS% %1" ) - set "CMDER_FLAGS=%CMDER_FLAGS% %1" shift goto var_loop @@ -318,7 +320,14 @@ echo. echo :: you can add your plugins to the cmder path like so echo :: set "PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%%" echo. -echo :: pass your custom arguments to init.bat, and you can parse them like so +echo :: Pass custom arguments to init.bat, and you can parse them like so: +echo :: If found... +echo :: echo %* | find /i "/noautorun">nul +echo :: if "%ERRORLEVEL%" == "0" ( +echo :: call vsCode +echo :: ) +echo. +echo :: If NOT found... echo :: echo %* | find /i "/noautorun">nul echo :: if "%ERRORLEVEL%" == "1" ( echo :: call vsCode From daa94c5462b864f4b0e6aab2ccc0eab5fe28a9b1 Mon Sep 17 00:00:00 2001 From: xiazeyu_2011 Date: Fri, 4 May 2018 20:14:40 +0800 Subject: [PATCH 04/23] Optimize comments of using arguments in user-profile.cmd --- vendor/init.bat | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index 7379dae..0b060f7 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -320,17 +320,15 @@ echo. echo :: you can add your plugins to the cmder path like so echo :: set "PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%%" echo. -echo :: Pass custom arguments to init.bat, and you can parse them like so: -echo :: If found... -echo :: echo %* | find /i "/noautorun">nul -echo :: if "%ERRORLEVEL%" == "0" ( -echo :: call vsCode -echo :: ) +echo :: arguments in this batch are passed from init.bat, you can parse them like so: echo. -echo :: If NOT found... -echo :: echo %* | find /i "/noautorun">nul -echo :: if "%ERRORLEVEL%" == "1" ( -echo :: call vsCode +echo :: echo %* | find /i "/customOption">nul +echo :: if "%ERRORLEVEL%" == "0" ( +echo :: echo found /customOption. +echo :: do something. +echo :: ) else ( +echo :: echo not found /customOption. +echo :: do something. echo :: ) echo. echo @echo off From bf6dae4a24477a59cb98bac06ac4b895f59f90d5 Mon Sep 17 00:00:00 2001 From: xiazeyu_2011 Date: Fri, 18 May 2018 20:32:05 +0800 Subject: [PATCH 05/23] feat: add have.bat as a wrapper --- bin/have.bat | 109 ++++++++++++++++++++++++++++++++++++++++++++++++ vendor/init.bat | 20 ++++----- 2 files changed, 118 insertions(+), 11 deletions(-) create mode 100644 bin/have.bat diff --git a/bin/have.bat b/bin/have.bat new file mode 100644 index 0000000..8007877 --- /dev/null +++ b/bin/have.bat @@ -0,0 +1,109 @@ +@echo off +setlocal + +if "%~1" equ "" goto :wrongSyntax + +if not defined CMDER_USER_FLAGS ( + exit /b +) + +set "haveBatNOT=false" +goto :parseArgument + +:doShift + shift + +:parseArgument +set "currenTarg=%~1" +if /i "%currenTarg%" == "/?" ( + goto :help +) else if /i "%currenTarg%" equ "/help" ( + goto :help +) else if /i "%currenTarg%" equ "/h" ( + goto :help +) else if /i "%currenTarg%" equ "NOT" ( + set "haveBatNOT=true" + goto :doShift +) else ( + if "%~1" equ "" goto :wrongSyntax + if "%~2" equ "" goto :wrongSyntax + set "haveBatArgName=%~1" + set "haveBatCommand=%~2" + goto :detect +) + +:detect +:: to avoid erroneous deteciton like "/do" "/doNOT", both have a "/do" +:: but if it works like "/do " "/doNOT ", "/do " won't match "/doN" +set "CMDER_USER_FLAGS=%CMDER_USER_FLAGS% " +set "haveBatArgName=%haveBatArgName% " +:: echo. +:: echo %CMDER_USER_FLAGS% +:: echo %haveBatNOT% +:: echo %haveBatArgName% +:: echo %haveBatCommand% +:: echo. +echo %CMDER_USER_FLAGS% | find /i "%haveBatArgName%">nul +if "%ERRORLEVEL%" == "0" ( + if "%haveBatNOT%" == "false" ( + call "%haveBatCommand%" + ) +) else ( + if "%haveBatNOT%" == "true" ( + call "%haveBatCommand%" + ) +) +exit /b + +:wrongSyntax +echo The syntax of the command is incorrect. +echo. +echo use /? for help +echo. +exit /b + +:help +echo have.bat +echo Handles with custom arguments for cmder's init.bat +echo written by xiazeyu, inspired DRSDavidSoft +echo. +echo Usage: +echo. +echo HAVE [NOT] argName command +echo. +echo NOT Specifies that have.bat should carry out +echo the command only if the condition is false. +echo. +echo argName Specifies which argument name is to detect. +echo. +echo command 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 Examples: +echo. +echo these examples are expected to be writted in /config/user-profile.cmd +echo it will use the environment varible "CMDER_USER_FLAGS" +echo. +echo Case 1: +echo. +echo The following command in user-profile.cmd would execute "notepad.exe" +echo. +echo call have "/startNotepad" "cmd /c 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" +echo. +echo call have NOT "/dontStartNotepad" "cmd /c start notepad.exe" +echo. +echo UNLESS you pass parameter to init.bat like: +echo. +echo init.bat /dontStartNotepad +echo. +exit /b diff --git a/vendor/init.bat b/vendor/init.bat index 0b060f7..ef5c449 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -308,28 +308,26 @@ if not exist "%initialConfig%" ( echo Creating user startup file: "%initialConfig%" ( echo :: use this file to run your own startup commands -echo :: use in front of the command to prevent printing the command +echo :: use in front of the command to prevent printing the command +echo. +echo :: the next one lines is for "have" shortcut, a custom arguments handler +echo :: don't remove it if you need it +echo set "CMDER_USER_FLAGS=%*" echo. echo :: uncomment this to have the ssh agent load when cmder starts echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-agent.cmd" echo. -echo :: uncomment this next two lines to use pageant as the ssh authentication agent +echo :: uncomment the next two lines to use pageant as the ssh authentication agent echo :: SET SSH_AUTH_SOCK=/tmp/.ssh-pageant-auth-sock echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-pageant.cmd" echo. echo :: you can add your plugins to the cmder path like so echo :: set "PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%%" echo. -echo :: arguments in this batch are passed from init.bat, you can parse them like so: +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 "have /?" echo. -echo :: echo %* | find /i "/customOption">nul -echo :: if "%ERRORLEVEL%" == "0" ( -echo :: echo found /customOption. -echo :: do something. -echo :: ) else ( -echo :: echo not found /customOption. -echo :: do something. -echo :: ) +echo :: have "/customOption" "your custom command" echo. echo @echo off ) >"%initialConfig%" From add82a247b5cf9ad21a9a0dd244227be6d2603ae Mon Sep 17 00:00:00 2001 From: xiazeyu_2011 Date: Fri, 18 May 2018 20:34:10 +0800 Subject: [PATCH 06/23] docs: update doc for have.bat --- README.md | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 66f5220..f3920fe 100644 --- a/README.md +++ b/README.md @@ -236,14 +236,76 @@ 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. ``` +### Handling with custom arguments when using init.bat + +You can pass custom arguments to `init.bat` and use `have.bat` (or `have` for shortcut) to detect it. + +It is useful when you have multiple modes to execute cmder. + +If you use + +```batch + +init.bat /startNotepad + +``` + +to start init.bat with custom argument(`/startNotepad`) and put + +```batch + +call have "/startNotepad" "cmd /c start notepad.exe"` + +``` + +into `/config/user-profile.cmd`, then `notepad.exe` will be executed, and once you use + +```batch + +init.bat + +``` + +the `notepad.exe` won't be executed. + +Detailed usage of `have` can be seen by typing `have /?` in cmder. + +This feature is usually for external execution. + +In my case, I use `cmder` as an **entry point** of my portable working system, + +and I [integrated VSCode with cmder](https://github.com/cmderdev/cmder/wiki/Seamless-VS-Code-Integration), it will **automatic execute VSCode** when I use `cmder.exe` to start. + +And when using integrated console in VSCode, VSCode **won't be executed again** as I use + +```json + +"terminal.integrated.shellArgs.windows": [ + "/k", + "%cmder_root%\\vendor\\init.bat", + "/noautorun" +], + +``` + +for `terminal.integrated.shellArgs.windows`, + +And here's the related fragment of my `user-profile.cmd`: + +```batch + +call have NOT "/noautorun" "cmd /c "start %cmder_root%\bin\vsCode\Code.exe --user-data-dir %vsCodeUserData% --extensions-dir %vsCodeExtensionsDir% %* %vsCodeUserData%\code.code-workspace" + +``` + ## Upgrading The process of upgrading Cmder depends on the version/build you are currently running -If you have a `[cmder_root]/config/user-conemu.xml`, you are running a newer version of Cmder, follow the below process: +If you have a `[cmder_root]/config/user-conemu.xml`, you are running a newer version of Cmder, follow the below process: 1. Exit all Cmder sessions and relaunch `[cmder_root]/cmder.exe`, this backs up your existing `[cmder_root]/vendor/conemu-maximus5/conemu.xml` to `[cmder_root]/config/user-conemu.xml`. - + * The `[cmder_root]/config/user-conemu.xml` contains any custom settings you have made using the 'Setup Tasks' settings dialog. 2. Exit all Cmder sessions and backup any files you have manually edited under `[cmder_root]/vendor`. @@ -253,7 +315,7 @@ If you have a `[cmder_root]/config/user-conemu.xml`, you are running a newer ver 3. Delete the `[cmder_root]/vendor` folder. 4. Extract the new `cmder.zip` or `cmder_mini.zip` into `[cmder_root]/` overwriting all files when prompted. -If you do not have a `[cmder_root]/config/user-conemu.xml`, you are running an older version of cmder, follow the below process: +If you do not have a `[cmder_root]/config/user-conemu.xml`, you are running an older version of cmder, follow the below process: 1. Exit all Cmder sessions and backup `[cmder_root]/vendor/conemu-maximus5/conemu.xml` to `[cmder_root]/config/user-conemu.xml`. From 0ce1db97d05259efe40f69665486a0c2f031d903 Mon Sep 17 00:00:00 2001 From: xiazeyu_2011 Date: Fri, 18 May 2018 21:02:36 +0800 Subject: [PATCH 07/23] fix: bug when no argument is passed in --- README.md | 2 +- bin/have.bat | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f3920fe..2751efe 100644 --- a/README.md +++ b/README.md @@ -294,7 +294,7 @@ And here's the related fragment of my `user-profile.cmd`: ```batch -call have NOT "/noautorun" "cmd /c "start %cmder_root%\bin\vsCode\Code.exe --user-data-dir %vsCodeUserData% --extensions-dir %vsCodeExtensionsDir% %* %vsCodeUserData%\code.code-workspace" +call have NOT "/noautorun" "cmd /c start %cmder_root%\bin\vsCode\Code.exe --user-data-dir %vsCodeUserData% --extensions-dir %vsCodeExtensionsDir% %* %vsCodeUserData%\code.code-workspace" ``` diff --git a/bin/have.bat b/bin/have.bat index 8007877..0e5ad21 100644 --- a/bin/have.bat +++ b/bin/have.bat @@ -4,7 +4,7 @@ setlocal if "%~1" equ "" goto :wrongSyntax if not defined CMDER_USER_FLAGS ( - exit /b + set "CMDER_USER_FLAGS= " ) set "haveBatNOT=false" From 861f99d64b7bf6e73948a87f0eae6972cede20d1 Mon Sep 17 00:00:00 2001 From: xiazeyu_2011 Date: Sun, 27 May 2018 10:22:44 +0800 Subject: [PATCH 08/23] rename /bin/have.bat to /vendor/lib/flag_exists.cmd Please use %flag_exists% instead of using have --- README.md | 12 +++--- vendor/init.bat | 9 +++-- bin/have.bat => vendor/lib/flag_exists.cmd | 45 ++++++++++++---------- 3 files changed, 35 insertions(+), 31 deletions(-) rename bin/have.bat => vendor/lib/flag_exists.cmd (69%) diff --git a/README.md b/README.md index 9b8f99d..0895c2c 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ Cmder, PowerShell, and Bash tabs all run on top of the Windows Console API and w You may however, choose to use an external installation of bash, such as Microsoft's [Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) (called WSL) or the [Cygwin](https://cygwin.com/) project which provides POSIX support on windows. -⚠ *NOTE:* Mintty tabs use a program called 'mintty' as the terminal emulator that is not based on the Windows Console API, rather it's rendered graphically by ConEmu. Mintty differs from the other tabs in that it supports xterm/xterm-256color TERM types, and does not work with ConEmu settings like color schemes and key bindings. As such, some differences in functionality are to be expected, such as Cmder not being able to apply a system-wide configuration to it. +⚠ *NOTE:* Mintty tabs use a program called 'mintty' as the terminal emulator that is not based on the Windows Console API, rather it's rendered graphically by ConEmu. Mintty differs from the other tabs in that it supports xterm/xterm-256color TERM types, and does not work with ConEmu settings like color schemes and key bindings. As such, some differences in functionality are to be expected, such as Cmder not being able to apply a system-wide configuration to it. As a result mintty specific config is done via the '[%USERPROFILE%|$HOME]/.minttyrc' file. You may read more about Mintty and its config file [here](https://github.com/mintty/mintty). @@ -248,7 +248,7 @@ Uncomment and edit the below line in the script to use Cmder config even when la ### Handling with custom arguments when using init.bat -You can pass custom arguments to `init.bat` and use `have.bat` (or `have` for shortcut) to detect it. +You can pass custom arguments to `init.bat` and use `%flag_exists%` to detect it. It is useful when you have multiple modes to execute cmder. @@ -264,7 +264,7 @@ to start init.bat with custom argument(`/startNotepad`) and put ```batch -call have "/startNotepad" "cmd /c start notepad.exe"` +call %flag_exists% "/startNotepad" "cmd /c start notepad.exe"` ``` @@ -278,7 +278,7 @@ init.bat the `notepad.exe` won't be executed. -Detailed usage of `have` can be seen by typing `have /?` in cmder. +Detailed usage of `%flag_exists%` can be seen by typing `%flag_exists% /?` in cmder. This feature is usually for external execution. @@ -304,11 +304,11 @@ And here's the related fragment of my `user-profile.cmd`: ```batch -call have NOT "/noautorun" "cmd /c start %cmder_root%\bin\vsCode\Code.exe --user-data-dir %vsCodeUserData% --extensions-dir %vsCodeExtensionsDir% %* %vsCodeUserData%\code.code-workspace" +call %flag_exists% NOT "/noautorun" "cmd /c start %cmder_root%\bin\vsCode\Code.exe --user-data-dir %vsCodeUserData% --extensions-dir %vsCodeExtensionsDir% %* %vsCodeUserData%\code.code-workspace" ``` -### 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). 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. diff --git a/vendor/init.bat b/vendor/init.bat index 5e4561e..4b1eef1 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -310,9 +310,10 @@ if not exist "%initialConfig%" ( echo :: use this file to run your own startup commands echo :: use in front of the command to prevent printing the command echo. -echo :: the next one lines is for "have" shortcut, a custom arguments handler +echo :: the next two lines is for "%%flag_exists%%" shortcut, a custom arguments handler echo :: don't remove it if you need it -echo set "CMDER_USER_FLAGS=%*" +echo set "CMDER_USER_FLAGS=%%*" +echo call "%%cmder_root%%\vendor\lib\flag_exists" echo. echo :: uncomment this to have the ssh agent load when cmder starts echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-agent.cmd" @@ -325,9 +326,9 @@ echo :: you can add your plugins to the cmder path like so echo :: set "PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%%" 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 "have /?" +echo :: more useage can be seen by typing "%%flag_exists%% /?" echo. -echo :: have "/customOption" "your custom command" +echo :: %%flag_exists%% "/customOption" "your custom command" echo. echo @echo off ) >"%initialConfig%" diff --git a/bin/have.bat b/vendor/lib/flag_exists.cmd similarity index 69% rename from bin/have.bat rename to vendor/lib/flag_exists.cmd index 0e5ad21..776aafb 100644 --- a/bin/have.bat +++ b/vendor/lib/flag_exists.cmd @@ -1,4 +1,5 @@ @echo off +set "flag_exists=%~dp0flag_exists" setlocal if "%~1" equ "" goto :wrongSyntax @@ -7,7 +8,7 @@ if not defined CMDER_USER_FLAGS ( set "CMDER_USER_FLAGS= " ) -set "haveBatNOT=false" +set "feNOT=false" goto :parseArgument :doShift @@ -22,13 +23,13 @@ if /i "%currenTarg%" == "/?" ( ) else if /i "%currenTarg%" equ "/h" ( goto :help ) else if /i "%currenTarg%" equ "NOT" ( - set "haveBatNOT=true" + set "feNOT=true" goto :doShift ) else ( if "%~1" equ "" goto :wrongSyntax if "%~2" equ "" goto :wrongSyntax - set "haveBatArgName=%~1" - set "haveBatCommand=%~2" + set "feArgName=%~1" + set "feCommand=%~2" goto :detect ) @@ -36,21 +37,21 @@ if /i "%currenTarg%" == "/?" ( :: to avoid erroneous deteciton like "/do" "/doNOT", both have a "/do" :: but if it works like "/do " "/doNOT ", "/do " won't match "/doN" set "CMDER_USER_FLAGS=%CMDER_USER_FLAGS% " -set "haveBatArgName=%haveBatArgName% " +set "feArgName=%feArgName% " :: echo. :: echo %CMDER_USER_FLAGS% -:: echo %haveBatNOT% -:: echo %haveBatArgName% -:: echo %haveBatCommand% +:: echo %feNOT% +:: echo %feArgName% +:: echo %feCommand% :: echo. -echo %CMDER_USER_FLAGS% | find /i "%haveBatArgName%">nul +echo %CMDER_USER_FLAGS% | find /i "%feArgName%">nul if "%ERRORLEVEL%" == "0" ( - if "%haveBatNOT%" == "false" ( - call "%haveBatCommand%" + if "%feNOT%" == "false" ( + call "%feCommand%" ) ) else ( - if "%haveBatNOT%" == "true" ( - call "%haveBatCommand%" + if "%feNOT%" == "true" ( + call "%feCommand%" ) ) exit /b @@ -63,22 +64,24 @@ echo. exit /b :help -echo have.bat -echo Handles with custom arguments for cmder's init.bat -echo written by xiazeyu, inspired DRSDavidSoft +echo. +echo %%flag_exists%% +echo. +echo Handles with custom arguments for cmder's init.bat. +echo written by xiazeyu, inspired DRSDavidSoft. echo. echo Usage: echo. -echo HAVE [NOT] argName command +echo %%flag_exists%% [NOT] argName command echo. -echo NOT Specifies that have.bat should carry out +echo NOT Specifies that %%flag_exists%% should carry out echo the command only if the condition is false. echo. echo argName Specifies which argument name is to detect. echo. echo command 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 use a pair of double quotation marks to echo wrap your command to avoid exceed expectation. echo. echo Examples: @@ -90,7 +93,7 @@ echo Case 1: echo. echo The following command in user-profile.cmd would execute "notepad.exe" echo. -echo call have "/startNotepad" "cmd /c start notepad.exe" +echo call %%flag_exists%% "/startNotepad" "cmd /c start notepad.exe" echo. echo if you pass parameter to init.bat like: echo. @@ -100,7 +103,7 @@ echo Case 2: echo. echo The following command in user-profile.cmd would execute "notepad.exe" echo. -echo call have NOT "/dontStartNotepad" "cmd /c start notepad.exe" +echo call %%flag_exists%% NOT "/dontStartNotepad" "cmd /c start notepad.exe" echo. echo UNLESS you pass parameter to init.bat like: echo. From b57e146e7a2b096f435c1855b451a53e72e3e1e2 Mon Sep 17 00:00:00 2001 From: xiazeyu_2011 Date: Tue, 17 Jul 2018 14:11:16 +0800 Subject: [PATCH 09/23] docs: migrated instructions to the wiki pages --- README.md | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/README.md b/README.md index 0895c2c..73d12ec 100644 --- a/README.md +++ b/README.md @@ -280,35 +280,8 @@ the `notepad.exe` won't be executed. Detailed usage of `%flag_exists%` can be seen by typing `%flag_exists% /?` in cmder. -This feature is usually for external execution. - -In my case, I use `cmder` as an **entry point** of my portable working system, - -and I [integrated VSCode with cmder](https://github.com/cmderdev/cmder/wiki/Seamless-VS-Code-Integration), it will **automatic execute VSCode** when I use `cmder.exe` to start. - -And when using integrated console in VSCode, VSCode **won't be executed again** as I use - -```json - -"terminal.integrated.shellArgs.windows": [ - "/k", - "%cmder_root%\\vendor\\init.bat", - "/noautorun" -], - -``` - -for `terminal.integrated.shellArgs.windows`, - -And here's the related fragment of my `user-profile.cmd`: - -```batch - -call %flag_exists% NOT "/noautorun" "cmd /c start %cmder_root%\bin\vsCode\Code.exe --user-data-dir %vsCodeUserData% --extensions-dir %vsCodeExtensionsDir% %* %vsCodeUserData%\code.code-workspace" - -``` - ### 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). 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. From b3200efa7ebabe3bbbd2a36b8941bbef935c1dda Mon Sep 17 00:00:00 2001 From: xiazeyu Date: Mon, 6 Aug 2018 11:25:27 +0800 Subject: [PATCH 10/23] doc: fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 73d12ec..50e1c16 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ The Cmder's user interface is also designed to be more eye pleasing, and you can | Argument | Description | | ------------------- | ----------------------------------------------------------------------- | | /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. | | /TASK [task_name] | Task to start after launch. | From f6c2d9c31e86666cae35ff17911c5495452b587b Mon Sep 17 00:00:00 2001 From: xiazeyu Date: Mon, 6 Aug 2018 13:09:59 +0800 Subject: [PATCH 11/23] refactor: reduce global varible useage, fixed quote issue, added parameters support --- README.md | 3 +- vendor/init.bat | 14 ++++---- vendor/lib/flag_exists.cmd | 73 ++++++++++++++++++++++++-------------- 3 files changed, 55 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 50e1c16..4dcdfd0 100644 --- a/README.md +++ b/README.md @@ -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' | | /user_aliases [file path] | File path pointing to user aliases. | '%CMDER_ROOT%\config\user-liases.cmd' | | /v | Enables verbose output. | not set | +| (custom arguments) | User defined arguments processed by `flag_exists`. Type `%flag_exists% /?` for more useage. | not set | ### 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: @@ -278,7 +279,7 @@ init.bat the `notepad.exe` won't be executed. -Detailed usage of `%flag_exists%` can be seen by typing `%flag_exists% /?` in cmder. +To see detailed usage of `%flag_exists%`, type `%flag_exists% /?` in cmder. ### Integrating Cmder with [Hyper](https://github.com/zeit/hyper), [Microsoft VS Code](https://code.visualstudio.com/), and your favorite IDEs diff --git a/vendor/init.bat b/vendor/init.bat index 4b1eef1..a9a553e 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -7,10 +7,11 @@ :: !!! Use "%CMDER_ROOT%\config\user-profile.cmd" to add your own startup commands :: Use /v command line arg or set to > 0 for verbose output to aid in debugging. +endlocal set verbose-output=0 set debug-output=0 set max_depth=1 -set "CMDER_FLAGS=" +set "CMDER_USER_FLAGS= " :: Find root dir if not defined CMDER_ROOT ( @@ -82,7 +83,7 @@ call "%cmder_root%\vendor\lib\lib_profile" set SVN_SSH=%2 shift ) else ( - set "CMDER_FLAGS=%CMDER_FLAGS% %1" + set "CMDER_USER_FLAGS=%1 %CMDER_USER_FLAGS%" ) shift goto var_loop @@ -293,14 +294,14 @@ if not defined HOME set "HOME=%USERPROFILE%" set "initialConfig=%CMDER_ROOT%\config\user-profile.cmd" if exist "%CMDER_ROOT%\config\user-profile.cmd" ( REM Create this file and place your own command in there - call "%CMDER_ROOT%\config\user-profile.cmd" %CMDER_FLAGS% + call "%CMDER_ROOT%\config\user-profile.cmd" ) if defined CMDER_USER_CONFIG ( set "initialConfig=%CMDER_USER_CONFIG%\user-profile.cmd" if exist "%CMDER_USER_CONFIG%\user-profile.cmd" ( REM Create this file and place your own command in there - call "%CMDER_USER_CONFIG%\user-profile.cmd" %CMDER_FLAGS% + call "%CMDER_USER_CONFIG%\user-profile.cmd" ) ) @@ -312,8 +313,7 @@ echo :: use in front of the command to prevent printing the command echo. echo :: the next two lines is for "%%flag_exists%%" shortcut, a custom arguments handler echo :: don't remove it if you need it -echo set "CMDER_USER_FLAGS=%%*" -echo call "%%cmder_root%%\vendor\lib\flag_exists" +echo call "%%cmder_root%%\vendor\lib\flag_exists" "/setPath" echo. echo :: uncomment this to have the ssh agent load when cmder starts echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-agent.cmd" @@ -328,7 +328,7 @@ 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 "%%flag_exists%% /?" echo. -echo :: %%flag_exists%% "/customOption" "your custom command" +echo :: %%flag_exists%% "/customOption" "command/program" echo. echo @echo off ) >"%initialConfig%" diff --git a/vendor/lib/flag_exists.cmd b/vendor/lib/flag_exists.cmd index 776aafb..c144340 100644 --- a/vendor/lib/flag_exists.cmd +++ b/vendor/lib/flag_exists.cmd @@ -1,59 +1,67 @@ @echo off -set "flag_exists=%~dp0flag_exists" 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" +set "feNot=false" goto :parseArgument :doShift shift :parseArgument -set "currenTarg=%~1" -if /i "%currenTarg%" == "/?" ( +set "currenArgu=%~1" +if /i "%currenArgu%" equ "/setPath" ( + :: set %flag_exists% shortcut + endlocal + set "flag_exists=%~dp0flag_exists" +) else if /i "%currenArgu%" == "/?" ( goto :help -) else if /i "%currenTarg%" equ "/help" ( +) else if /i "%currenArgu%" equ "/help" ( goto :help -) else if /i "%currenTarg%" equ "/h" ( +) else if /i "%currenArgu%" equ "/h" ( goto :help -) else if /i "%currenTarg%" equ "NOT" ( - set "feNOT=true" +) else if /i "%currenArgu%" equ "NOT" ( + set "feNot=true" goto :doShift ) else ( if "%~1" equ "" goto :wrongSyntax if "%~2" equ "" goto :wrongSyntax - set "feArgName=%~1" + set "feFlagName=%~1" set "feCommand=%~2" + if not "%~3" equ "" ( + set "feParam=%~3" + ) goto :detect ) :detect -:: to avoid erroneous deteciton like "/do" "/doNOT", both have a "/do" -:: but if it works like "/do " "/doNOT ", "/do " won't match "/doN" -set "CMDER_USER_FLAGS=%CMDER_USER_FLAGS% " -set "feArgName=%feArgName% " +:: 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 %feArgName% +:: echo %feFlagName% :: echo %feCommand% +:: echo %feParam% :: echo. -echo %CMDER_USER_FLAGS% | find /i "%feArgName%">nul +echo %CMDER_USER_FLAGS% | find /i "%feFlagName%">nul if "%ERRORLEVEL%" == "0" ( if "%feNOT%" == "false" ( - call "%feCommand%" + call %feCommand% %feParam% ) ) else ( if "%feNOT%" == "true" ( - call "%feCommand%" + call %feCommand% %feParam% ) ) +endlocal exit /b :wrongSyntax @@ -61,6 +69,7 @@ echo The syntax of the command is incorrect. echo. echo use /? for help echo. +endlocal exit /b :help @@ -72,17 +81,26 @@ echo written by xiazeyu, inspired DRSDavidSoft. echo. echo Usage: echo. -echo %%flag_exists%% [NOT] argName command +echo %%flag_exists%% [/setPath] [NOT] flagName command/program [parameters] echo. -echo NOT Specifies that %%flag_exists%% should carry out -echo the command only if the condition is false. +echo setPath Generate a global varible %%flag_exists%% for +echo quicker use. Following arguments will be ignored. echo. -echo argName Specifies which argument name is to detect. +echo NOT Specifies that %%flag_exists%% should carry out +echo the command only if the flag is missing. echo. -echo command 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 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. @@ -93,7 +111,7 @@ echo Case 1: echo. echo The following command in user-profile.cmd would execute "notepad.exe" echo. -echo call %%flag_exists%% "/startNotepad" "cmd /c start notepad.exe" +echo call %%flag_exists%% "/startNotepad" "start" "notepad.exe" echo. echo if you pass parameter to init.bat like: echo. @@ -103,10 +121,11 @@ echo Case 2: echo. echo The following command in user-profile.cmd would execute "notepad.exe" echo. -echo call %%flag_exists%% NOT "/dontStartNotepad" "cmd /c start notepad.exe" +echo call %%flag_exists%% NOT "/dontStartNotepad" "start" "notepad.exe" echo. echo UNLESS you pass parameter to init.bat like: echo. echo init.bat /dontStartNotepad echo. +endlocal exit /b From f4ee915678cef7dfdb664627212e27041537a593 Mon Sep 17 00:00:00 2001 From: xiazeyu Date: Mon, 6 Aug 2018 13:21:45 +0800 Subject: [PATCH 12/23] docs: update to latest useage --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 00008b4..b97204e 100644 --- a/README.md +++ b/README.md @@ -265,7 +265,7 @@ to start init.bat with custom argument(`/startNotepad`) and put ```batch -call %flag_exists% "/startNotepad" "cmd /c start notepad.exe"` +call %flag_exists% "/startNotepad" "start" "notepad.exe"` ``` From 39f47870a339c99e7526920ec3e06b875db8890b Mon Sep 17 00:00:00 2001 From: xiazeyu Date: Mon, 6 Aug 2018 16:05:31 +0800 Subject: [PATCH 13/23] chore: unite slash --- vendor/init.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/init.bat b/vendor/init.bat index a419482..99a86e7 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -320,7 +320,7 @@ echo :: use in front of the command to prevent printing the command echo. echo :: the next two lines is for "%%flag_exists%%" shortcut, a custom arguments handler echo :: don't remove it if you need it -echo call "%%cmder_root%%\vendor\lib\flag_exists" "/setPath" +echo call "%%cmder_root%%/vendor/lib/flag_exists" "/setPath" echo. echo :: uncomment this to have the ssh agent load when cmder starts echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-agent.cmd" From 669e99760261b02968fc43e7793b9e2661e78186 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sat, 15 Sep 2018 12:52:23 -0500 Subject: [PATCH 14/23] flag_exists.cmd to flag_exec.cmd, also to lib as an option --- .../flag_exists.cmd => bin/flag_exec.cmd} | 0 vendor/lib/lib_profile.cmd | 131 ++++++++++++++++++ 2 files changed, 131 insertions(+) rename vendor/{lib/flag_exists.cmd => bin/flag_exec.cmd} (100%) diff --git a/vendor/lib/flag_exists.cmd b/vendor/bin/flag_exec.cmd similarity index 100% rename from vendor/lib/flag_exists.cmd rename to vendor/bin/flag_exec.cmd diff --git a/vendor/lib/lib_profile.cmd b/vendor/lib/lib_profile.cmd index 98bc9f0..55fe62c 100644 --- a/vendor/lib/lib_profile.cmd +++ b/vendor/lib/lib_profile.cmd @@ -44,3 +44,134 @@ exit /b ) popd exit /b + +:flag_exec + @echo off + setlocal + + if "%~1" equ "" call :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 "flag_exists=%~dp0flag_exists" + ) else if /i "%currenArgu%" == "/?" ( + call :help + ) else if /i "%currenArgu%" equ "/help" ( + call :help + ) else if /i "%currenArgu%" equ "/h" ( + call :help + ) else if /i "%currenArgu%" equ "NOT" ( + set "feNot=true" + goto :doShift + ) else ( + if "%~1" equ "" call :wrongSyntax + if "%~2" equ "" call :wrongSyntax + set "feFlagName=%~1" + set "feCommand=%~2" + if not "%~3" equ "" ( + set "feParam=%~3" + ) + ) + + :: 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" ( + call %feCommand% %feParam% + ) + ) else ( + if "%feNOT%" == "true" ( + call %feCommand% %feParam% + ) + ) + endlocal + exit /b + + :wrongSyntax + echo The syntax of the command is incorrect. + echo. + echo use /? for help + echo. + endlocal + exit /b + + :help + echo. + echo %%flag_exists%% + echo. + echo Handles with custom arguments for cmder's init.bat. + echo written by xiazeyu, inspired DRSDavidSoft. + echo. + echo Usage: + echo. + echo %%flag_exists%% [/setPath] [NOT] flagName command/program [parameters] + echo. + echo setPath Generate a global varible %%flag_exists%% for + echo quicker use. Following arguments will be ignored. + echo. + echo NOT Specifies that %%flag_exists%% 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 writted in /config/user-profile.cmd + echo it will use the environment varible "CMDER_USER_FLAGS" + echo. + echo Case 1: + echo. + echo The following command in user-profile.cmd would execute "notepad.exe" + echo. + echo call %%flag_exists%% "/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" + echo. + echo call %%flag_exists%% NOT "/dontStartNotepad" "start" "notepad.exe" + echo. + echo UNLESS you pass parameter to init.bat like: + echo. + echo init.bat /dontStartNotepad + echo. + endlocal + exit /b From 9dce9d0f62ca0546347bd490a95722db2eedc92d Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sat, 15 Sep 2018 13:55:54 -0500 Subject: [PATCH 15/23] added exit codes --- README.md | 8 +++---- vendor/bin/{flag_exec.cmd => cexec.cmd} | 30 ++++++++++++++----------- vendor/init.bat | 1 + 3 files changed, 22 insertions(+), 17 deletions(-) rename vendor/bin/{flag_exec.cmd => cexec.cmd} (77%) diff --git a/README.md b/README.md index d50c61f..9e8e711 100644 --- a/README.md +++ b/README.md @@ -148,7 +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` | | `/user_aliases [file path]` | File path pointing to user aliases. | `%CMDER_ROOT%\config\user-liases.cmd` | | `/v` | Enables verbose output. | not set | -| (custom arguments) | User defined arguments processed by `flag_exists`. Type `%flag_exists% /?` for more useage. | not set | +| (custom arguments) | User defined arguments processed by `cexec`. Type `cexec /?` for more useage. | not set | ### 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: @@ -249,7 +249,7 @@ Uncomment and edit the below line in the script to use Cmder config even when la ### Handling with custom arguments when using init.bat -You can pass custom arguments to `init.bat` and use `%flag_exists%` to detect it. +You can pass custom arguments to `init.bat` and use `cexec` to detect it. It is useful when you have multiple modes to execute cmder. @@ -265,7 +265,7 @@ to start init.bat with custom argument(`/startNotepad`) and put ```batch -call %flag_exists% "/startNotepad" "start" "notepad.exe"` +call cexec "/startNotepad" "start" "notepad.exe"` ``` @@ -279,7 +279,7 @@ init.bat the `notepad.exe` won't be executed. -To see detailed usage of `%flag_exists%`, type `%flag_exists% /?` in cmder. +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 diff --git a/vendor/bin/flag_exec.cmd b/vendor/bin/cexec.cmd similarity index 77% rename from vendor/bin/flag_exec.cmd rename to vendor/bin/cexec.cmd index c144340..2b1c09f 100644 --- a/vendor/bin/flag_exec.cmd +++ b/vendor/bin/cexec.cmd @@ -19,9 +19,10 @@ set "currenArgu=%~1" if /i "%currenArgu%" equ "/setPath" ( :: set %flag_exists% shortcut endlocal - set "flag_exists=%~dp0flag_exists" + set "ccall=call %~dp0cexec.cmd" + set "cexec=%~dp0cexec.cmd" ) else if /i "%currenArgu%" == "/?" ( - goto :help + call :help ) else if /i "%currenArgu%" equ "/help" ( goto :help ) else if /i "%currenArgu%" equ "/h" ( @@ -55,14 +56,16 @@ echo %CMDER_USER_FLAGS% | find /i "%feFlagName%">nul if "%ERRORLEVEL%" == "0" ( if "%feNOT%" == "false" ( call %feCommand% %feParam% + exit /b 0 ) ) else ( if "%feNOT%" == "true" ( call %feCommand% %feParam% + exit /b 0 ) ) endlocal -exit /b +exit /b 1 :wrongSyntax echo The syntax of the command is incorrect. @@ -74,22 +77,22 @@ exit /b :help echo. -echo %%flag_exists%% +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 %%flag_exists%% [/setPath] [NOT] flagName command/program [parameters] +echo cexec [NOT] flagName command/program [parameters] echo. -echo setPath Generate a global varible %%flag_exists%% for +echo /setPath Generate a global varible %%cexec%% for echo quicker use. Following arguments will be ignored. echo. -echo NOT Specifies that %%flag_exists%% should carry out +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 /[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. @@ -104,16 +107,17 @@ echo to wrap your flag name to avoid exceed expectation. echo. echo Examples: echo. -echo these examples are expected to be writted in /config/user-profile.cmd -echo it will use the environment varible "CMDER_USER_FLAGS" +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" echo. -echo call %%flag_exists%% "/startNotepad" "start" "notepad.exe" +echo call cexec "/startNotepad" "start" "notepad.exe" echo. -echo if you pass parameter to init.bat like: +echo If you pass parameter to init.bat like: echo. echo init.bat /startNotepad echo. @@ -121,7 +125,7 @@ echo Case 2: echo. echo The following command in user-profile.cmd would execute "notepad.exe" echo. -echo call %%flag_exists%% NOT "/dontStartNotepad" "start" "notepad.exe" +echo call cexec NOT "/dontStartNotepad" "start" "notepad.exe" echo. echo UNLESS you pass parameter to init.bat like: echo. diff --git a/vendor/init.bat b/vendor/init.bat index f2f3880..6690c40 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -29,6 +29,7 @@ if not defined CMDER_ROOT ( :: Remove trailing '\' from %CMDER_ROOT% 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_path" call "%cmder_root%\vendor\lib\lib_console" From 0be94725bd8b138b9e3635e2eb1fb2cc4e8e75fb Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sat, 15 Sep 2018 15:06:13 -0500 Subject: [PATCH 16/23] readme.md --- README.md | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 9e8e711..a0548f7 100644 --- a/README.md +++ b/README.md @@ -247,37 +247,51 @@ 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. ``` -### Handling with custom arguments when using init.bat +### Customizing user sessions using `init.bat` custom arguments. -You can pass custom arguments to `init.bat` and use `cexec` to detect it. +You can pass custom arguments to `init.bat` and use `cexec` in your `user_profile.cmd` to evaluate these +arguments then execute commands based on a particular flag being detected or not. -It is useful when you have multiple modes to execute cmder. +`init.bat` creates two shortcuts for using `cexec` in your profile scripts. -If you use + Evaluate flags, runs commands if found, and returns to the calling script and continues. -```batch + ``` + ccall=call C:\Users\user\cmderdev\vendor\bin\cexec.cmd + ``` -init.bat /startNotepad + Example: `%ccall% /startnotepad start notepad.exe` + + Evaluate 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` -to start init.bat with custom argument(`/startNotepad`) and put +It is useful when you have multiple tasks to execute `cmder` and need it to initialize +the session differently depending on the task chosen. -```batch +To conditionally start `notepad.exe` when you start a specific `cmder` task: -call cexec "/startNotepad" "start" "notepad.exe"` +* Press win+alt+t +* Click `+` to add a new task. +* Add the below to the `Commands` block: -``` + ```batch + + cmd.exe /k ""%ConEmuDir%\..\init.bat" /startnotepad" + + ``` -into `/config/user-profile.cmd`, then `notepad.exe` will be executed, and once you use +* Add the below to your `%cmder_root%\config\user_profile.cmd` -```batch - -init.bat - -``` - -the `notepad.exe` won't be executed. + ```batch + + %ccall% "/startNotepad" "start" "notepad.exe"` + + ``` To see detailed usage of `cexec`, type `cexec /?` in cmder. From 4aec21ce199c1eb11370cbb6c09a10e2c48ae6e0 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sat, 15 Sep 2018 15:10:35 -0500 Subject: [PATCH 17/23] readme.md --- vendor/bin/cexec.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/bin/cexec.cmd b/vendor/bin/cexec.cmd index 2b1c09f..fc0ac47 100644 --- a/vendor/bin/cexec.cmd +++ b/vendor/bin/cexec.cmd @@ -22,7 +22,7 @@ if /i "%currenArgu%" equ "/setPath" ( set "ccall=call %~dp0cexec.cmd" set "cexec=%~dp0cexec.cmd" ) else if /i "%currenArgu%" == "/?" ( - call :help + goto :help ) else if /i "%currenArgu%" equ "/help" ( goto :help ) else if /i "%currenArgu%" equ "/h" ( From 86544c91886d956d6ff07df18daf070c524c1ee1 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sat, 15 Sep 2018 15:11:50 -0500 Subject: [PATCH 18/23] readme.md --- vendor/bin/cexec.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/bin/cexec.cmd b/vendor/bin/cexec.cmd index fc0ac47..b4bb81e 100644 --- a/vendor/bin/cexec.cmd +++ b/vendor/bin/cexec.cmd @@ -84,7 +84,7 @@ echo written by xiazeyu, inspired DRSDavidSoft. echo. echo Usage: echo. -echo cexec [NOT] flagName command/program [parameters] +echo cexec /setPath [NOT] flagName command/program [parameters] echo. echo /setPath Generate a global varible %%cexec%% for echo quicker use. Following arguments will be ignored. From f84da84e15201aaf121cea8de3322834d58da85c Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sat, 15 Sep 2018 15:12:45 -0500 Subject: [PATCH 19/23] cleanup --- vendor/lib/lib_profile.cmd | 130 ------------------------------------- 1 file changed, 130 deletions(-) diff --git a/vendor/lib/lib_profile.cmd b/vendor/lib/lib_profile.cmd index 55fe62c..9bf08b9 100644 --- a/vendor/lib/lib_profile.cmd +++ b/vendor/lib/lib_profile.cmd @@ -45,133 +45,3 @@ exit /b popd exit /b -:flag_exec - @echo off - setlocal - - if "%~1" equ "" call :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 "flag_exists=%~dp0flag_exists" - ) else if /i "%currenArgu%" == "/?" ( - call :help - ) else if /i "%currenArgu%" equ "/help" ( - call :help - ) else if /i "%currenArgu%" equ "/h" ( - call :help - ) else if /i "%currenArgu%" equ "NOT" ( - set "feNot=true" - goto :doShift - ) else ( - if "%~1" equ "" call :wrongSyntax - if "%~2" equ "" call :wrongSyntax - set "feFlagName=%~1" - set "feCommand=%~2" - if not "%~3" equ "" ( - set "feParam=%~3" - ) - ) - - :: 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" ( - call %feCommand% %feParam% - ) - ) else ( - if "%feNOT%" == "true" ( - call %feCommand% %feParam% - ) - ) - endlocal - exit /b - - :wrongSyntax - echo The syntax of the command is incorrect. - echo. - echo use /? for help - echo. - endlocal - exit /b - - :help - echo. - echo %%flag_exists%% - echo. - echo Handles with custom arguments for cmder's init.bat. - echo written by xiazeyu, inspired DRSDavidSoft. - echo. - echo Usage: - echo. - echo %%flag_exists%% [/setPath] [NOT] flagName command/program [parameters] - echo. - echo setPath Generate a global varible %%flag_exists%% for - echo quicker use. Following arguments will be ignored. - echo. - echo NOT Specifies that %%flag_exists%% 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 writted in /config/user-profile.cmd - echo it will use the environment varible "CMDER_USER_FLAGS" - echo. - echo Case 1: - echo. - echo The following command in user-profile.cmd would execute "notepad.exe" - echo. - echo call %%flag_exists%% "/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" - echo. - echo call %%flag_exists%% NOT "/dontStartNotepad" "start" "notepad.exe" - echo. - echo UNLESS you pass parameter to init.bat like: - echo. - echo init.bat /dontStartNotepad - echo. - endlocal - exit /b From 564ef5220e168893899ac1e6f25fba6a455ae065 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sat, 15 Sep 2018 16:25:31 -0500 Subject: [PATCH 20/23] allow conditionally setting environment variables --- vendor/bin/cexec.cmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/bin/cexec.cmd b/vendor/bin/cexec.cmd index b4bb81e..2efcacd 100644 --- a/vendor/bin/cexec.cmd +++ b/vendor/bin/cexec.cmd @@ -55,12 +55,12 @@ set "feFlagName=%feFlagName% " echo %CMDER_USER_FLAGS% | find /i "%feFlagName%">nul if "%ERRORLEVEL%" == "0" ( if "%feNOT%" == "false" ( - call %feCommand% %feParam% + endlocal && call %feCommand% %feParam% exit /b 0 ) ) else ( if "%feNOT%" == "true" ( - call %feCommand% %feParam% + endlocal && call %feCommand% %feParam% exit /b 0 ) ) From bda09bc274b93ba26990d5b490a014184668dae8 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sun, 16 Sep 2018 16:23:22 -0500 Subject: [PATCH 21/23] init.bat update for cexec --- vendor/init.bat | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index 6690c40..9365bd9 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -7,7 +7,6 @@ :: !!! Use "%CMDER_ROOT%\config\user_profile.cmd" to add your own startup commands :: Use /v command line arg or set to > 0 for verbose output to aid in debugging. -endlocal set verbose_output=0 set debug_output=0 set max_depth=1 @@ -333,10 +332,6 @@ if not exist "%initialConfig%" ( echo :: use this file to run your own startup commands echo :: use in front of the command to prevent printing the command echo. -echo :: the next two lines is for "%%flag_exists%%" shortcut, a custom arguments handler -echo :: don't remove it if you need it -echo call "%%cmder_root%%/vendor/lib/flag_exists" "/setPath" -echo. echo :: uncomment this to have the ssh agent load when cmder starts echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-agent.cmd" echo. @@ -348,9 +343,9 @@ echo :: you can add your plugins to the cmder path like so echo :: set "PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%%" 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 "%%flag_exists%% /?" +echo :: more useage can be seen by typing "cexec /?" echo. -echo :: %%flag_exists%% "/customOption" "command/program" +echo :: %%ccall%% "/customOption" "command/program" echo. echo @echo off ) >"%initialConfig%" From 103d0a6cea871d10c3df992861b833c155c6fbb2 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Mon, 24 Sep 2018 18:51:55 -0500 Subject: [PATCH 22/23] more headers --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a0548f7..15e7267 100644 --- a/README.md +++ b/README.md @@ -249,26 +249,26 @@ Uncomment and edit the below line in the script to use Cmder config even when la ### Customizing user sessions using `init.bat` custom arguments. -You can pass custom arguments to `init.bat` and use `cexec` in your `user_profile.cmd` to evaluate these +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` in your profile scripts. +`init.bat` creates two shortcuts for using `cexec.cmd` in your profile scripts. - Evaluate flags, runs commands if found, and returns to the calling script and continues. +#### `%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 - ``` +``` +ccall=call C:\Users\user\cmderdev\vendor\bin\cexec.cmd +``` - Example: `%ccall% /startnotepad start notepad.exe` - - Evaluate flags, runs commands if found, and does not return to the calling script. +Example: `%ccall% /startnotepad start notepad.exe` - ``` - cexec=C:\Users\user\cmderdev\vendor\bin\cexec.cmd - ``` - - Example: `%cexec% /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. From 8ff459b309cbcd10314041eb8296679925b0a785 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Mon, 24 Sep 2018 19:07:48 -0500 Subject: [PATCH 23/23] fixes --- vendor/bin/cexec.cmd | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vendor/bin/cexec.cmd b/vendor/bin/cexec.cmd index 2efcacd..3193f4f 100644 --- a/vendor/bin/cexec.cmd +++ b/vendor/bin/cexec.cmd @@ -86,7 +86,7 @@ echo Usage: echo. echo cexec /setPath [NOT] flagName command/program [parameters] echo. -echo /setPath Generate a global varible %%cexec%% for +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 @@ -113,9 +113,9 @@ 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" +echo The following command in `user_profile.cmd` would execute "notepad.exe" and continue running the `user_profile.cmd` echo. -echo call cexec "/startNotepad" "start" "notepad.exe" +echo "%ccall%" "/startNotepad" "start" "notepad.exe" echo. echo If you pass parameter to init.bat like: echo. @@ -123,9 +123,9 @@ echo init.bat /startNotepad echo. echo Case 2: echo. -echo The following command in user-profile.cmd would execute "notepad.exe" +echo The following command in `user_profile.cmd` would execute "notepad.exe" and stop running the `user_profile.cmd` echo. -echo call cexec NOT "/dontStartNotepad" "start" "notepad.exe" +echo "%cexec%" NOT "/dontStartNotepad" "start" "notepad.exe" echo. echo UNLESS you pass parameter to init.bat like: echo.