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

Rework alias command to not to use external tools #358

Merged
merged 5 commits into from
Jan 8, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 27 additions & 6 deletions bin/alias.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
@echo off

set ALIASES=%CMDER_ROOT%\config\aliases

if ["%*"] == [""] echo Use /? for help & echo. & goto :p_show
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
Expand All @@ -14,21 +20,36 @@ if not ["%_temp%"] == ["%_temp2%"] (
goto:eof
)

echo %* >> "%CMDER_ROOT%\config\aliases"
doskey /macrofile="%CMDER_ROOT%\config\aliases"
perl "%CMDER_ROOT%\scripts\clean_aliases.pl"
echo Alias created
:: replace already defined alias
findstr /b /v /i "%_temp%=" "%ALIASES%" >> "%ALIASES%.tmp"
echo %* >> "%ALIASES%.tmp" && type "%ALIASES%.tmp" > "%ALIASES%" & @del /f /q "%ALIASES%.tmp"
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="%CMDER_ROOT%\config\aliases"
doskey /macrofile="%ALIASES%"
echo Aliases reloaded
goto:eof

:p_show
type "%ALIASES%" || echo No aliases found at "%ALIASES%"
goto :eof

:p_help
echo.Usage:
echo. alias name=full command
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:
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.
Expand Down
28 changes: 0 additions & 28 deletions bin/unalias.bat

This file was deleted.

1 change: 1 addition & 0 deletions config/aliases
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ls=ls --color $*
pwd=cd
clear=cls
history=cat %CMDER_ROOT%\config\.history
unalias=alias /d $1
36 changes: 0 additions & 36 deletions scripts/clean_aliases.pl

This file was deleted.