Add /d option to alias command that removes existing alias

* Remove separate unalias script and add `unalias` alias ^) for `alias /d`
This commit is contained in:
an-selm 2014-12-24 22:14:59 +03:00
parent e224d133f3
commit 0ae09e9a4a
3 changed files with 9 additions and 28 deletions

View File

@ -4,6 +4,8 @@ set ALIASES="%CMDER_ROOT%\config\aliases"
if ["%1"] == ["/?"] goto:p_help
if ["%1"] == ["/reload"] goto:p_reload
:: /d flag for delete existing alias
if ["%1"] == ["/d"] goto:p_del %*
if ["%2"] == [""] echo Insufficient parameters. & goto:p_help
::validate alias
setlocal
@ -24,6 +26,12 @@ doskey /macrofile=%ALIASES%
endlocal
goto:eof
:p_del
findstr /b /v /i "%2=" %ALIASES% >> %ALIASES%.tmp
type %ALIASES%.tmp > %ALIASES% & @del /f /q %ALIASES%.tmp
doskey /macrofile=%ALIASES%
goto:eof
:p_reload
doskey /macrofile=%ALIASES%
echo Aliases reloaded

View File

@ -1,28 +0,0 @@
@echo off
if ["%1"] == ["/?"] goto:p_help
if ["%1"] == [""] echo Insufficient parameters. & goto:p_help
setlocal
:: Check if alias exists
doskey /macros | findstr /b %1= >NUL || goto :p_not_found
:: Remove alias from current shell
doskey %1=
:: Remove alias from aliases file
copy /y "%CMDER_ROOT%\config\aliases" "%TEMP%\aliases.prev" >NUL
type "%TEMP%\aliases.prev" | findstr /b /v %1= > "%CMDER_ROOT%\config\aliases"
echo Alias removed
endlocal
goto:eof
:p_not_found
echo Alias not defined.
goto:eof
:p_help
echo.Usage:
echo. unalias name
echo. For more information, read DOSKEY/?

View File

@ -4,3 +4,4 @@ ls=ls --color $*
pwd=cd
clear=cls
history=cat %CMDER_ROOT%\config\.history
unalias=alias /d $1