From 3e40c803311292055e2e74132d184706b5d19e4f Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Mon, 1 Apr 2019 16:58:45 -0400 Subject: [PATCH 1/7] new alias create syntax --- vendor/bin/alias.cmd | 82 +++++++++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 20 deletions(-) diff --git a/vendor/bin/alias.cmd b/vendor/bin/alias.cmd index 1a1739d5e..ee64ad4f3 100644 --- a/vendor/bin/alias.cmd +++ b/vendor/bin/alias.cmd @@ -14,6 +14,8 @@ if "%~1" == "" echo Use /? for help & echo. & goto :p_show rem #region parseargument goto parseargument +set args= + :do_shift shift @@ -22,10 +24,15 @@ goto parseargument if /i "%currentarg%" equ "/f" ( set ALIASES=%~2 + set ALT_ALIASES=%~2 shift goto :do_shift ) else if /i "%currentarg%" == "/reload" ( goto :p_reload + ) else if "%currentarg%" equ "/H" ( + goto :p_help + ) else if "%currentarg%" equ "/h" ( + goto :p_help ) else if "%currentarg%" equ "/?" ( goto :p_help ) else if /i "%currentarg%" equ "/d" ( @@ -43,11 +50,28 @@ goto parseargument doskey /macros | %WINDIR%\System32\findstr /b %currentarg%= && exit /b echo insufficient parameters. goto :p_help + ) else if "%currentarg%" == "create" ( + set action=create + if [%ALT_ALIASES%] neq [] ( + echo 1 + for /f "tokens=1,2,3,* usebackq" %%G in (`echo %*`) do ( + set args=%%J + ) + ) else ( + echo 2 + for /f "tokens=1,2,* usebackq" %%G in (`echo %*`) do ( + set args=%%H %%I + ) + ) ) else ( :: handle quotes within command definition, e.g. quoted long file names set _x=%* ) ) + +:: echo _x=%_x% +:: echo args=%args% + rem #endregion parseargument if "%ALIASES%" neq "%CMDER_ROOT%\config\user_aliases.cmd" ( @@ -63,25 +87,38 @@ if "%ALIASES%" neq "%CMDER_ROOT%\config\user_aliases.cmd" ( ) ) -:: validate alias -for /f "delims== tokens=1,* usebackq" %%G in (`echo "%_x%"`) do ( - set alias_name=%%G - set alias_value=%%H -) - -:: leading quotes added while validating -set alias_name=%alias_name:~1% +:: create with multiple parameters +if [%action%] == [create] ( + if not ["%args%"] == [""] ( + for /f "tokens=1,* usebackq" %%G in (`echo %args%`) do ( + set alias_name=%%G + set alias_value=%%H + ) + ) +) else ( + :: validate alias + echo %_x% + set x=!_x:%=^^%! + echo !_x! + for /f "delims== tokens=1,* usebackq" %%G in (`echo "!_x!"`) do ( + set alias_name=%%G + set alias_value=%%H + ) -:: trailing quotes added while validating -set alias_value=%alias_value:~0,-1% + :: leading quotes added while validating + set alias_name=!alias_name:~1! + + :: trailing quotes added while validating + set alias_value=!alias_value:~1,-1! +) ::remove spaces set _temp=%alias_name: =% if not ["%_temp%"] == ["%alias_name%"] ( - echo Your alias name can not contain a space - endlocal - exit /b + echo Your alias name can not contain a space + endlocal + exit /b ) :: replace already defined alias @@ -111,21 +148,26 @@ exit /b :p_help echo.Usage: echo. -echo. alias [options] [alias=full command] +echo. alias [options] [alias=alias command] or [[create [alias] [alias command]]] echo. echo.Options: echo. +echo. Note: Options MUST precede the alias definition. +echo. echo. /d [alias] Delete an [alias]. echo. /f [macrofile] Path to the [macrofile] you want to store the new alias in. echo. Default: %cmder_root%\config\user_aliases.cmd echo. /reload Reload the aliases file. Can be used with /f argument. echo. Default: %cmder_root%\config\user_aliases.cmd echo. -echo. If alias is called with no parameters, it will display the list of existing aliases. +echo. If alias is called with no parameters, it will display the list of existing aliases. +echo. +echo. In the alias command, you can use the following notations: +echo. +echo. ^^^^^^^^%% - '%%' in env vars must be escaped if preserving the variable in the alias is desired. +echo. $* - allows the alias to assume all the parameters of the supplied command. +echo. $1-$9 - Allows you to seperate parameter by number, much like %%1 in batch. +echo. $T - Command seperator, allowing you to string several commands together into one alias. echo. -echo. In the command, you can use the following notations: -echo. $* allows the alias to assume all the parameters of the supplied command. -echo. $1-$9 Allows you to seperate parameter by number, much like %%1 in batch. -echo. $T is the command seperator, allowing you to string several commands together into one alias. -echo. For more information, read DOSKEY/? +echo. For more information, read DOSKEY /? exit /b From cf134604bb465673de068bea6a14a9a318952905 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Mon, 1 Apr 2019 17:31:46 -0400 Subject: [PATCH 2/7] fixes --- vendor/bin/alias.cmd | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/vendor/bin/alias.cmd b/vendor/bin/alias.cmd index 5000dc737..9d58ecc9a 100644 --- a/vendor/bin/alias.cmd +++ b/vendor/bin/alias.cmd @@ -24,7 +24,6 @@ set args= if /i "%currentarg%" equ "/f" ( set ALIASES=%~2 - set ALT_ALIASES=%~2 shift goto :do_shift ) else if /i "%currentarg%" == "/reload" ( @@ -52,13 +51,11 @@ set args= goto :p_help ) else if "%currentarg%" == "create" ( set action=create - if [%ALT_ALIASES%] neq [] ( - echo 1 + if ["%ALIASES%"] neq ["%CMDER_ROOT%\config\user_aliases.cmd"] ( for /f "tokens=1,2,3,* usebackq" %%G in (`echo %*`) do ( set args=%%J ) ) else ( - echo 2 for /f "tokens=1,2,* usebackq" %%G in (`echo %*`) do ( set args=%%H %%I ) @@ -85,29 +82,11 @@ if "%ALIASES%" neq "%CMDER_ROOT%\config\user_aliases.cmd" ( ) :: create with multiple parameters -<<<<<<< HEAD if [%action%] == [create] ( if not ["%args%"] == [""] ( for /f "tokens=1,* usebackq" %%G in (`echo %args%`) do ( set alias_name=%%G set alias_value=%%H -======= -if [%1] == [create] ( - if not [%2] == [] ( - if not [%3] == [] ( - set _x=%1=%2 - :: if command create was submitted - set alias_name=%~2 - shift - shift - echo %* - set alias_value=%* - - for /f "tokens=1,2,* usebackq" %%G in (`echo %*`) do ( - set alias_name=%%H - set alias_value=%%I - ) ->>>>>>> ac2082d56d59b3731824e11227eae396278b9f37 ) ) ) else ( From f20eca01ac386dd0d930376ece307f3b87482de2 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Mon, 1 Apr 2019 17:34:00 -0400 Subject: [PATCH 3/7] fixes --- vendor/bin/alias.cmd.orig | 183 -------------------------------------- 1 file changed, 183 deletions(-) delete mode 100644 vendor/bin/alias.cmd.orig diff --git a/vendor/bin/alias.cmd.orig b/vendor/bin/alias.cmd.orig deleted file mode 100644 index e915e6b13..000000000 --- a/vendor/bin/alias.cmd.orig +++ /dev/null @@ -1,183 +0,0 @@ -@echo off - - -if "%ALIASES%" == "" ( - set ALIASES="%CMDER_ROOT%\config\user_aliases.cmd" -) - -setlocal enabledelayedexpansion - -if "%~1" == "" echo Use /? for help & echo. & goto :p_show - -:: check command usage - -rem #region parseargument -goto parseargument - -set args= - -:do_shift - shift - -:parseargument - set currentarg=%~1 - - if /i "%currentarg%" equ "/f" ( - set ALIASES=%~2 - shift - goto :do_shift - ) else if /i "%currentarg%" == "/reload" ( - goto :p_reload - ) else if "%currentarg%" equ "/H" ( - goto :p_help - ) else if "%currentarg%" equ "/h" ( - goto :p_help - ) else if "%currentarg%" equ "/?" ( - goto :p_help - ) else if /i "%currentarg%" equ "/d" ( - if "%~2" neq "" ( - if "%~3" equ "" ( - :: /d flag for delete existing alias - call :p_del %~2 - shift - goto :eof - ) - ) - ) else if "%currentarg%" neq "" ( - if "%~2" equ "" ( - :: Show the specified alias - doskey /macros | %WINDIR%\System32\findstr /b %currentarg%= && exit /b - echo insufficient parameters. - goto :p_help - ) else if "%currentarg%" == "create" ( - set action=create - if ["%ALIASES%"] neq ["%CMDER_ROOT%\config\user_aliases.cmd"] ( - for /f "tokens=1,2,3,* usebackq" %%G in (`echo %*`) do ( - set args=%%J - ) - ) else ( - for /f "tokens=1,2,* usebackq" %%G in (`echo %*`) do ( - set args=%%H %%I - ) - ) - ) else ( - :: handle quotes within command definition, e.g. quoted long file names - set _x=%* - ) - ) -<<<<<<< HEAD - -======= ->>>>>>> 67b374ad378bee1b9157b9a0b20c8e667ec6c6da -rem #endregion parseargument - -if "%ALIASES%" neq "%CMDER_ROOT%\config\user_aliases.cmd" ( - set _x=!_x:/f "%ALIASES%" =! - - if not exist "%ALIASES%" ( - echo ;= @echo off>"%ALIASES%" - echo ;= rem Call DOSKEY and use this file as the macrofile>>"%ALIASES%" - echo ;= %%SystemRoot%%\system32\doskey /listsize=1000 /macrofile=%%0%%>>"%ALIASES%" - echo ;= rem In batch mode, jump to the end of the file>>"%ALIASES%" - echo ;= goto:eof>>"%ALIASES%" - echo ;= Add aliases below here>>"%ALIASES%" - ) -) - -<<<<<<< HEAD -:: create with multiple parameters -if [%action%] == [create] ( - if not ["%args%"] == [""] ( - for /f "tokens=1,* usebackq" %%G in (`echo %args%`) do ( - set alias_name=%%G - set alias_value=%%H - ) - ) -) else ( - :: validate alias - echo %_x% - set x=!_x:%=^^%! - echo !_x! - for /f "delims== tokens=1,* usebackq" %%G in (`echo "!_x!"`) do ( - set alias_name=%%G - set alias_value=%%H - ) - - :: leading quotes added while validating - set alias_name=!alias_name:~1! - - :: trailing quotes added while validating - set alias_value=!alias_value:~1,-1! -======= -:: validate alias -for /f "delims== tokens=1,* usebackq" %%G in (`echo "%_x%"`) do ( - set alias_name=%%G - set alias_value=%%H ->>>>>>> 67b374ad378bee1b9157b9a0b20c8e667ec6c6da -) - -:: leading quotes added while validating -set alias_name=%alias_name:~1% - -:: trailing quotes added while validating -set alias_value=%alias_value:~0,-1% - -::remove spaces -set _temp=%alias_name: =% - -if not ["%_temp%"] == ["%alias_name%"] ( - echo Your alias name can not contain a space - endlocal - exit /b -) - -:: replace already defined alias -%WINDIR%\System32\findstr /b /v /i "%alias_name%=" "%ALIASES%" >> "%ALIASES%.tmp" -echo %alias_name%=%alias_value% >> "%ALIASES%.tmp" && type "%ALIASES%.tmp" > "%ALIASES%" & @del /f /q "%ALIASES%.tmp" -doskey /macrofile="%ALIASES%" -endlocal -exit /b - -:p_del -set del_alias=%~1 -%WINDIR%\System32\findstr /b /v /i "%del_alias%=" "%ALIASES%" >> "%ALIASES%.tmp" -type "%ALIASES%".tmp > "%ALIASES%" & @del /f /q "%ALIASES%.tmp" -doskey %del_alias%= -doskey /macrofile="%ALIASES%" -goto:eof - -:p_reload -doskey /macrofile="%ALIASES%" -echo Aliases reloaded -exit /b - -:p_show -doskey /macros|%WINDIR%\System32\findstr /v /r "^;=" | sort -exit /b - -:p_help -echo.Usage: -echo. -echo. alias [options] [alias=alias command] or [[create [alias] [alias command]]] -echo. -echo.Options: -echo. -echo. Note: Options MUST precede the alias definition. -echo. -echo. /d [alias] Delete an [alias]. -echo. /f [macrofile] Path to the [macrofile] you want to store the new alias in. -echo. Default: %cmder_root%\config\user_aliases.cmd -echo. /reload Reload the aliases file. Can be used with /f argument. -echo. Default: %cmder_root%\config\user_aliases.cmd -echo. -echo. If alias is called with no parameters, it will display the list of existing aliases. -echo. -echo. In the alias command, you can use the following notations: -echo. -echo. ^^^^^^^^%% - '%%' in env vars must be escaped if preserving the variable in the alias is desired. -echo. $* - allows the alias to assume all the parameters of the supplied command. -echo. $1-$9 - Allows you to seperate parameter by number, much like %%1 in batch. -echo. $T - Command seperator, allowing you to string several commands together into one alias. -echo. -echo. For more information, read DOSKEY /? -exit /b From 528bbea7f5f54fe7a152e50382d7ba97eac66ed3 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Mon, 1 Apr 2019 22:10:21 -0400 Subject: [PATCH 4/7] fixes --- vendor/bin/alias.cmd | 51 ++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/vendor/bin/alias.cmd b/vendor/bin/alias.cmd index 149996a8f..502c11ade 100644 --- a/vendor/bin/alias.cmd +++ b/vendor/bin/alias.cmd @@ -14,8 +14,6 @@ if "%~1" == "" echo Use /? for help & echo. & goto :p_show rem #region parseargument goto parseargument -set args= - :do_shift shift @@ -24,6 +22,7 @@ set args= if /i "%currentarg%" equ "/f" ( set ALIASES=%~2 + set _f=%~2 shift goto :do_shift ) else if /i "%currentarg%" == "/reload" ( @@ -50,19 +49,27 @@ set args= echo insufficient parameters. goto :p_help ) else if "%currentarg%" == "create" ( + set _x=%* + + set _x=!_x:^^=^^^^! set action=create - if ["%ALIASES%"] neq ["%CMDER_ROOT%\config\user_aliases.cmd"] ( - for /f "tokens=1,2,3,* usebackq" %%G in (`echo %*`) do ( - set args=%%J + if ["%_f%"] neq [""] ( + for /f "tokens=1,2,3,* usebackq" %%G in (`echo !_x!`) do ( + set _x=%%J ) ) else ( - for /f "tokens=1,2,* usebackq" %%G in (`echo %*`) do ( - set args=%%H %%I + for /f "tokens=1,2,* usebackq" %%G in (`echo !_x!`) do ( + set _x=%%H %%I ) ) ) else ( - :: handle quotes within command definition, e.g. quoted long file names set _x=%* + if ["%_f%"] neq [""] ( + set _x=!_x:^^=^^^^! + for /f "tokens=1,2,* usebackq" %%G in (`echo !_x!`) do ( + set _x=%%I + ) + ) ) ) @@ -81,20 +88,16 @@ if "%ALIASES%" neq "%CMDER_ROOT%\config\user_aliases.cmd" ( ) ) -<<<<<<< HEAD :: create with multiple parameters if [%action%] == [create] ( - if not ["%args%"] == [""] ( - for /f "tokens=1,* usebackq" %%G in (`echo %args%`) do ( - set alias_name=%%G - set alias_value=%%H - ) + for /f "tokens=1,* usebackq" %%G in (`echo !_x!`) do ( + set alias_name=%%G + set alias_value=%%H ) ) else ( :: validate alias - echo %_x% - set x=!_x:%=^^%! - echo !_x! + rem set _x=!_x:%=^^%! + for /f "delims== tokens=1,* usebackq" %%G in (`echo "!_x!"`) do ( set alias_name=%%G set alias_value=%%H @@ -104,21 +107,9 @@ if [%action%] == [create] ( set alias_name=!alias_name:~1! :: trailing quotes added while validating - set alias_value=!alias_value:~1,-1! -======= -:: validate alias -for /f "delims== tokens=1,* usebackq" %%G in (`echo "%_x%"`) do ( - set alias_name=%%G - set alias_value=%%H ->>>>>>> 67b374ad378bee1b9157b9a0b20c8e667ec6c6da + set alias_value=!alias_value:~0,-1! ) -:: leading quotes added while validating -set alias_name=%alias_name:~1% - -:: trailing quotes added while validating -set alias_value=%alias_value:~0,-1% - ::remove spaces set _temp=%alias_name: =% From ab3f0b76fb5506bff818cee0184b0dc09344475f Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Mon, 1 Apr 2019 22:17:53 -0400 Subject: [PATCH 5/7] fixes --- vendor/bin/alias.cmd | 2 -- 1 file changed, 2 deletions(-) diff --git a/vendor/bin/alias.cmd b/vendor/bin/alias.cmd index 502c11ade..999e5a017 100644 --- a/vendor/bin/alias.cmd +++ b/vendor/bin/alias.cmd @@ -96,8 +96,6 @@ if [%action%] == [create] ( ) ) else ( :: validate alias - rem set _x=!_x:%=^^%! - for /f "delims== tokens=1,* usebackq" %%G in (`echo "!_x!"`) do ( set alias_name=%%G set alias_value=%%H From 9b9bb13f6a694e366c076b94f7726b8a18b3e2b1 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sun, 5 May 2019 17:06:44 -0400 Subject: [PATCH 6/7] fix commnd line help --- vendor/bin/alias.cmd | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/vendor/bin/alias.cmd b/vendor/bin/alias.cmd index 999e5a017..e5269f5db 100644 --- a/vendor/bin/alias.cmd +++ b/vendor/bin/alias.cmd @@ -144,26 +144,36 @@ exit /b :p_help echo.Usage: echo. -echo. alias [options] [alias=alias command] or [[create [alias] [alias command]]] +echo. alias [options] [alias=alias command] +echo. +echo OR +echo. +echo. alias create [alias] [alias command] echo. echo.Options: echo. -echo. Note: Options MUST precede the alias definition. +echo. Note: Options MUST precede the alias definition. echo. -echo. /d [alias] Delete an [alias]. -echo. /f [macrofile] Path to the [macrofile] you want to store the new alias in. -echo. Default: %cmder_root%\config\user_aliases.cmd -echo. /reload Reload the aliases file. Can be used with /f argument. -echo. Default: %cmder_root%\config\user_aliases.cmd +echo. /d [alias] Delete an [alias]. +echo. /f [macrofile] Path to the [macrofile] you want to store the new alias in. +echo. Default: %cmder_root%\config\user_aliases.cmd +echo. /reload Reload the aliases file. Can be used with /f argument. +echo. Default: %cmder_root%\config\user_aliases.cmd echo. -echo. If alias is called with no parameters, it will display the list of existing aliases. +echo. If alias is called with no parameters, it will display the list of existing +echo. aliases. echo. echo. In the alias command, you can use the following notations: echo. -echo. ^^^^^^^^%% - '%%' in env vars must be escaped if preserving the variable in the alias is desired. -echo. $* - allows the alias to assume all the parameters of the supplied command. -echo. $1-$9 - Allows you to seperate parameter by number, much like %%1 in batch. -echo. $T - Command seperator, allowing you to string several commands together into one alias. +echo. ^^^^^^^^%% - %% signs in env vars must be escaped if preserving the variable +echo. in he alias is desired. Variables in aliases surrounded by double +echo. quotes only require '^^%%' vs '^^^^^^^^%%' +echo. $* - allows the alias to assume all the parameters of the supplied +echo. command. +echo. $1-$9 - Allows you to seperate parameter by number, much like %%1 in +echo. batch. +echo. $T - Command seperator, allowing you to string several commands +echo. together into one alias. echo. echo. For more information, read DOSKEY /? exit /b From 5f9f3560c8cb6798230d06ca2c517ebf4b481020 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sun, 5 May 2019 17:11:31 -0400 Subject: [PATCH 7/7] fix commnd line help --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34ae8edc0..bde41afa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,13 @@ * Turn this on in existing Cmder using `clink set history_io 1` * Allow clink disable by setting CMDER_CLINK=0 before starting task +### Adds + +* Pull Request: [#2072](https://github.com/cmderdev/cmder/pull/2072) + * New alias create [alias] [alias command] syntax + * Based on [#1750](https://github.com/cmderdev/cmder/pull/1750) + * Syntax: `alias create [alias] [alias command]` + ## [1.3.11](https://github.com/cmderdev/cmder/tree/v1.3.11) (2018-12-22) ### Fixes