mirror of
https://github.com/cmderdev/cmder.git
synced 2024-11-10 17:59:11 +08:00
Merge pull request #300 from melku/clean_aliases_script
Clean aliases script
This commit is contained in:
commit
20c9ba207d
@ -15,6 +15,7 @@ if not ["%_temp%"] == ["%_temp2%"] (
|
|||||||
|
|
||||||
echo %* >> "%CMDER_ROOT%\config\aliases"
|
echo %* >> "%CMDER_ROOT%\config\aliases"
|
||||||
doskey /macrofile="%CMDER_ROOT%\config\aliases"
|
doskey /macrofile="%CMDER_ROOT%\config\aliases"
|
||||||
|
perl "%CMDER_ROOT%\scripts\clean_aliases.pl"
|
||||||
echo Alias created
|
echo Alias created
|
||||||
endlocal
|
endlocal
|
||||||
goto:eof
|
goto:eof
|
||||||
|
36
scripts/clean_aliases.pl
Normal file
36
scripts/clean_aliases.pl
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# 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);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user