From 5bd0c29c25b80ba84872db1c26fccfd02d75913e Mon Sep 17 00:00:00 2001 From: melchior Date: Thu, 16 Oct 2014 01:00:59 -0400 Subject: [PATCH] Convert the clean alias script to perl --- bin/alias.bat | 2 +- scripts/clean_aliases.pl | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 scripts/clean_aliases.pl diff --git a/bin/alias.bat b/bin/alias.bat index a323fec..ae3966a 100644 --- a/bin/alias.bat +++ b/bin/alias.bat @@ -15,7 +15,7 @@ if not ["%_temp%"] == ["%_temp2%"] ( echo %* >> "%CMDER_ROOT%\config\aliases" doskey /macrofile="%CMDER_ROOT%\config\aliases" -lua "%CMDER_ROOT%\scripts\clean_aliases.lua" +perl "%CMDER_ROOT%\scripts\clean_aliases.pl" echo Alias created endlocal goto:eof diff --git a/scripts/clean_aliases.pl b/scripts/clean_aliases.pl new file mode 100644 index 0000000..77756f3 --- /dev/null +++ b/scripts/clean_aliases.pl @@ -0,0 +1,32 @@ +# 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; + } +} +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); +