Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias #2072

Merged
merged 9 commits into from
May 5, 2019
Merged

Alias #2072

Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 59 additions & 21 deletions vendor/bin/alias.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ goto parseargument

if /i "%currentarg%" equ "/f" (
set ALIASES=%~2
set _f=%~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" (
Expand All @@ -43,11 +48,31 @@ goto parseargument
doskey /macros | %WINDIR%\System32\findstr /b %currentarg%= && exit /b
echo insufficient parameters.
goto :p_help
) else if "%currentarg%" == "create" (
set _x=%*

set _x=!_x:^^=^^^^!
set action=create
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 !_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
)
)
)
)

rem #endregion parseargument

if "%ALIASES%" neq "%CMDER_ROOT%\config\user_aliases.cmd" (
Expand All @@ -63,25 +88,33 @@ 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] (
for /f "tokens=1,* usebackq" %%G in (`echo !_x!`) do (
set alias_name=%%G
set alias_value=%%H
)
) else (
:: validate alias
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:~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
echo Your alias name can not contain a space
endlocal
exit /b
)

:: replace already defined alias
Expand Down Expand Up @@ -111,21 +144,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