new alias create syntax

This commit is contained in:
Dax T. Games 2019-04-01 16:58:45 -04:00
parent f2b26352b4
commit 3e40c80331

82
vendor/bin/alias.cmd vendored
View File

@ -14,6 +14,8 @@ if "%~1" == "" echo Use /? for help & echo. & goto :p_show
rem #region parseargument rem #region parseargument
goto parseargument goto parseargument
set args=
:do_shift :do_shift
shift shift
@ -22,10 +24,15 @@ goto parseargument
if /i "%currentarg%" equ "/f" ( if /i "%currentarg%" equ "/f" (
set ALIASES=%~2 set ALIASES=%~2
set ALT_ALIASES=%~2
shift shift
goto :do_shift goto :do_shift
) else if /i "%currentarg%" == "/reload" ( ) else if /i "%currentarg%" == "/reload" (
goto :p_reload goto :p_reload
) else if "%currentarg%" equ "/H" (
goto :p_help
) else if "%currentarg%" equ "/h" (
goto :p_help
) else if "%currentarg%" equ "/?" ( ) else if "%currentarg%" equ "/?" (
goto :p_help goto :p_help
) else if /i "%currentarg%" equ "/d" ( ) else if /i "%currentarg%" equ "/d" (
@ -43,11 +50,28 @@ goto parseargument
doskey /macros | %WINDIR%\System32\findstr /b %currentarg%= && exit /b doskey /macros | %WINDIR%\System32\findstr /b %currentarg%= && exit /b
echo insufficient parameters. echo insufficient parameters.
goto :p_help 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 ( ) else (
:: handle quotes within command definition, e.g. quoted long file names :: handle quotes within command definition, e.g. quoted long file names
set _x=%* set _x=%*
) )
) )
:: echo _x=%_x%
:: echo args=%args%
rem #endregion parseargument rem #endregion parseargument
if "%ALIASES%" neq "%CMDER_ROOT%\config\user_aliases.cmd" ( if "%ALIASES%" neq "%CMDER_ROOT%\config\user_aliases.cmd" (
@ -63,25 +87,38 @@ if "%ALIASES%" neq "%CMDER_ROOT%\config\user_aliases.cmd" (
) )
) )
:: validate alias :: create with multiple parameters
for /f "delims== tokens=1,* usebackq" %%G in (`echo "%_x%"`) do ( if [%action%] == [create] (
set alias_name=%%G if not ["%args%"] == [""] (
set alias_value=%%H 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!
) )
:: 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 ::remove spaces
set _temp=%alias_name: =% set _temp=%alias_name: =%
if not ["%_temp%"] == ["%alias_name%"] ( if not ["%_temp%"] == ["%alias_name%"] (
echo Your alias name can not contain a space echo Your alias name can not contain a space
endlocal endlocal
exit /b exit /b
) )
:: replace already defined alias :: replace already defined alias
@ -111,21 +148,26 @@ exit /b
:p_help :p_help
echo.Usage: echo.Usage:
echo. echo.
echo. alias [options] [alias=full command] echo. alias [options] [alias=alias command] or [[create [alias] [alias command]]]
echo. echo.
echo.Options: echo.Options:
echo. echo.
echo. Note: Options MUST precede the alias definition.
echo.
echo. /d [alias] Delete an [alias]. echo. /d [alias] Delete an [alias].
echo. /f [macrofile] Path to the [macrofile] you want to store the new alias in. echo. /f [macrofile] Path to the [macrofile] you want to store the new alias in.
echo. Default: %cmder_root%\config\user_aliases.cmd echo. Default: %cmder_root%\config\user_aliases.cmd
echo. /reload Reload the aliases file. Can be used with /f argument. echo. /reload Reload the aliases file. Can be used with /f argument.
echo. Default: %cmder_root%\config\user_aliases.cmd echo. Default: %cmder_root%\config\user_aliases.cmd
echo. 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.
echo. In the command, you can use the following notations: echo. In the alias command, you can use the following notations:
echo. $* allows the alias to assume all the parameters of the supplied command. echo.
echo. $1-$9 Allows you to seperate parameter by number, much like %%1 in batch. echo. ^^^^^^^^%% - '%%' in env vars must be escaped if preserving the variable in the alias is desired.
echo. $T is the command seperator, allowing you to string several commands together into one alias. echo. $* - allows the alias to assume all the parameters of the supplied command.
echo. For more information, read DOSKEY/? 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 exit /b