2013-07-09 15:43:50 +08:00
|
|
|
@echo off
|
2014-12-25 02:40:21 +08:00
|
|
|
|
2016-03-02 10:30:51 +08:00
|
|
|
|
|
|
|
if "%aliases%" == "" (
|
|
|
|
set ALIASES=%CMDER_ROOT%\config\user-aliases.cmd
|
|
|
|
)
|
|
|
|
|
|
|
|
setlocal enabledelayedexpansion
|
|
|
|
|
|
|
|
if "%~1" == "" echo Use /? for help & echo. & goto :p_show
|
2014-12-25 02:40:21 +08:00
|
|
|
|
2015-02-23 13:48:33 +08:00
|
|
|
:: check command usage
|
2016-03-02 10:30:51 +08:00
|
|
|
|
|
|
|
rem #region parseargument
|
|
|
|
goto parseargument
|
|
|
|
|
|
|
|
: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 "/?" (
|
|
|
|
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 | findstr /b %currentarg%= && exit /b
|
|
|
|
echo insufficient parameters.
|
|
|
|
goto :p_help
|
|
|
|
) else (
|
|
|
|
:: handle quotes within command definition, e.g. quoted long file names
|
|
|
|
set _x=%*
|
|
|
|
)
|
|
|
|
)
|
|
|
|
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%"
|
|
|
|
)
|
2014-11-12 01:08:32 +08:00
|
|
|
)
|
2013-11-27 11:36:48 +08:00
|
|
|
|
2015-02-23 13:48:33 +08:00
|
|
|
:: validate alias
|
2017-02-10 02:53:35 +08:00
|
|
|
for /f "delims== tokens=1,* usebackq" %%G in (`echo "%_x%"`) do (
|
2016-03-02 10:30:51 +08:00
|
|
|
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:~0,-1%
|
2013-11-27 11:36:48 +08:00
|
|
|
|
2016-03-02 10:30:51 +08:00
|
|
|
::remove spaces
|
|
|
|
set _temp=%alias_name: =%
|
|
|
|
|
|
|
|
if not ["%_temp%"] == ["%alias_name%"] (
|
2013-11-27 11:36:48 +08:00
|
|
|
echo Your alias name can not contain a space
|
|
|
|
endlocal
|
2016-03-02 10:30:51 +08:00
|
|
|
exit /b
|
2013-11-27 11:36:48 +08:00
|
|
|
)
|
|
|
|
|
2014-12-25 02:40:21 +08:00
|
|
|
:: replace already defined alias
|
2016-03-02 10:30:51 +08:00
|
|
|
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"
|
2014-12-25 03:20:16 +08:00
|
|
|
doskey /macrofile="%ALIASES%"
|
2013-11-27 11:36:48 +08:00
|
|
|
endlocal
|
2016-03-02 10:30:51 +08:00
|
|
|
exit /b
|
2013-11-27 11:36:48 +08:00
|
|
|
|
2014-12-25 03:14:59 +08:00
|
|
|
:p_del
|
2016-03-02 10:30:51 +08:00
|
|
|
set del_alias=%~1
|
|
|
|
findstr /b /v /i "%del_alias%=" "%ALIASES%" >> "%ALIASES%.tmp"
|
2014-12-25 03:20:16 +08:00
|
|
|
type "%ALIASES%".tmp > "%ALIASES%" & @del /f /q "%ALIASES%.tmp"
|
2016-03-02 10:30:51 +08:00
|
|
|
doskey %del_alias%=
|
2014-12-25 03:14:59 +08:00
|
|
|
doskey /macrofile=%ALIASES%
|
|
|
|
goto:eof
|
|
|
|
|
2014-10-25 03:39:37 +08:00
|
|
|
:p_reload
|
2014-12-25 03:20:16 +08:00
|
|
|
doskey /macrofile="%ALIASES%"
|
2014-10-25 03:39:37 +08:00
|
|
|
echo Aliases reloaded
|
2016-03-02 10:30:51 +08:00
|
|
|
exit /b
|
2014-10-25 03:39:37 +08:00
|
|
|
|
2014-12-25 03:16:26 +08:00
|
|
|
:p_show
|
2016-03-02 10:30:51 +08:00
|
|
|
doskey /macros|findstr /v /r "^;=" | sort
|
|
|
|
exit /b
|
2014-12-25 03:16:26 +08:00
|
|
|
|
2013-11-27 11:36:48 +08:00
|
|
|
:p_help
|
|
|
|
echo.Usage:
|
2016-03-02 10:30:51 +08:00
|
|
|
echo.
|
|
|
|
echo. alias [options] [alias=full command]
|
|
|
|
echo.
|
|
|
|
echo.Options:
|
|
|
|
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.
|
2015-01-09 01:43:45 +08:00
|
|
|
echo.
|
|
|
|
echo. In the command, you can use the following notations:
|
2013-11-27 11:36:48 +08:00
|
|
|
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/?
|
2016-03-02 10:30:51 +08:00
|
|
|
exit /b
|