From e224d133f3c0a89ff27f7164d5a653fce7508a4d Mon Sep 17 00:00:00 2001 From: an-selm Date: Wed, 24 Dec 2014 21:40:21 +0300 Subject: [PATCH] Rework alias command to handle duplicates * Removed unnecessary perl script --- bin/alias.bat | 13 ++++++++----- scripts/clean_aliases.pl | 36 ------------------------------------ 2 files changed, 8 insertions(+), 41 deletions(-) delete mode 100644 scripts/clean_aliases.pl diff --git a/bin/alias.bat b/bin/alias.bat index c9eeec6..9f54ebb 100644 --- a/bin/alias.bat +++ b/bin/alias.bat @@ -1,4 +1,7 @@ @echo off + +set ALIASES="%CMDER_ROOT%\config\aliases" + if ["%1"] == ["/?"] goto:p_help if ["%1"] == ["/reload"] goto:p_reload if ["%2"] == [""] echo Insufficient parameters. & goto:p_help @@ -14,15 +17,15 @@ 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_reload -doskey /macrofile="%CMDER_ROOT%\config\aliases" +doskey /macrofile=%ALIASES% echo Aliases reloaded goto:eof diff --git a/scripts/clean_aliases.pl b/scripts/clean_aliases.pl deleted file mode 100644 index c7cf699..0000000 --- a/scripts/clean_aliases.pl +++ /dev/null @@ -1,36 +0,0 @@ -# Cmder adds aliases to its aliases file without caring for duplicates. -# This can result in the aliases file becoming bloated. This script cleans -#the aliases file. -use Env; - -my %aliases; -my $alias_file = $CMDER_ROOT . "/config/aliases"; - -# First step -# Read the aliases file line by line, and put every entry in -# a dictionary. The newer aliases being the last, the new will -# always be kept over the old. -open (my $file_handle, '<', $alias_file) or die "cannot open '$alias_file' $!"; -while(my $line = <$file_handle>) -{ - if ($line =~ /([^=\s<>]+)=(.*)/) - { - $aliases{ $1 } = $2; - } - else - { - print "Invalid alias: $line" - } -} -close($file_handle); - - -# Second step -# Write back the aliases. Sort them to make the file look nice. -open(my $file_handle, '>', $alias_file) or die "cannot open '$alias_file' $!"; -foreach my $key (sort keys %aliases) -{ - print $file_handle "$key=$aliases{ $key }\n"; -} -close($file_handle); -