2013-07-09 15:43:50 +08:00
|
|
|
@echo off
|
2014-12-25 02:40:21 +08:00
|
|
|
|
2014-12-25 03:20:16 +08:00
|
|
|
set ALIASES=%CMDER_ROOT%\config\aliases
|
2014-12-25 02:40:21 +08:00
|
|
|
|
2014-12-25 03:16:26 +08:00
|
|
|
if ["%*"] == [""] echo Use /? for help & echo. & goto :p_show
|
2013-11-27 11:36:48 +08:00
|
|
|
if ["%1"] == ["/?"] goto:p_help
|
2014-10-25 03:39:37 +08:00
|
|
|
if ["%1"] == ["/reload"] goto:p_reload
|
2015-03-18 18:56:25 +08:00
|
|
|
:: /d flag for delete existing alias
|
|
|
|
if ["%1"] == ["/d"] goto:p_del %*
|
2014-11-12 01:08:32 +08:00
|
|
|
:: if arg is an existing alias, display it
|
|
|
|
if ["%2"] == [""] (
|
|
|
|
doskey /macros | findstr /b %1= && goto:eof
|
|
|
|
echo Insufficient parameters. & goto:p_help
|
|
|
|
)
|
|
|
|
|
2013-11-27 11:36:48 +08:00
|
|
|
::validate alias
|
|
|
|
setlocal
|
|
|
|
for /f "delims== tokens=1" %%G in ("%*") do set _temp2=%%G
|
|
|
|
|
|
|
|
set _temp=%_temp2: =%
|
|
|
|
|
|
|
|
if not ["%_temp%"] == ["%_temp2%"] (
|
|
|
|
echo Your alias name can not contain a space
|
|
|
|
endlocal
|
|
|
|
goto:eof
|
|
|
|
)
|
|
|
|
|
2014-12-25 02:40:21 +08:00
|
|
|
:: replace already defined alias
|
2014-12-25 03:20:16 +08:00
|
|
|
findstr /b /v /i "%_temp%=" "%ALIASES%" >> "%ALIASES%.tmp"
|
|
|
|
echo %* >> "%ALIASES%.tmp" && type "%ALIASES%.tmp" > "%ALIASES%" & @del /f /q "%ALIASES%.tmp"
|
|
|
|
doskey /macrofile="%ALIASES%"
|
2013-11-27 11:36:48 +08:00
|
|
|
endlocal
|
|
|
|
goto:eof
|
|
|
|
|
2014-12-25 03:14:59 +08:00
|
|
|
:p_del
|
2014-12-25 03:20:16 +08:00
|
|
|
findstr /b /v /i "%2=" "%ALIASES%" >> "%ALIASES%.tmp"
|
|
|
|
type "%ALIASES%".tmp > "%ALIASES%" & @del /f /q "%ALIASES%.tmp"
|
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
|
|
|
|
goto:eof
|
|
|
|
|
2014-12-25 03:16:26 +08:00
|
|
|
:p_show
|
2014-12-25 03:20:16 +08:00
|
|
|
type "%ALIASES%" || echo No aliases found at "%ALIASES%"
|
2014-12-25 03:16:26 +08:00
|
|
|
goto :eof
|
|
|
|
|
2013-11-27 11:36:48 +08:00
|
|
|
:p_help
|
|
|
|
echo.Usage:
|
2015-01-09 01:43:45 +08:00
|
|
|
echo. alias [/reload] [/d] [name=full command]
|
|
|
|
echo. /reload Reload the aliases file
|
|
|
|
echo. /d Delete an alias (must be followed by the alias name)
|
|
|
|
echo.
|
|
|
|
echo. If alias is called with any parameters, it will display the list of existing aliases.
|
|
|
|
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/?
|