#!/usr/bin/perl # # path_filter.pl - parse the PATH variable, and return a new path string with all # the duplicates removed, and any entries in the IGNORE hash removed. # # Win/DOS doesn't care much about case sensitivity, so we'll map everything to lower # case on storage so we can remove dups in different cases (specifically for the # case of C:\Windows\System32 vs C:\Windows\system32) # # 20110309 roboticus use strict; use warnings; my $DBG=0; my %IGNORE = map { lc($_)=>0 } ( "/DOS/c/Program Files/TortoiseSVN/bin", "/DOS/c/Program Files/QuickTime/QTSystem", "/DOS/c/WINDOWS/system32/WindowsPowerShell/v1.0", . . . snip! . . . # WBEM=Web-Based Enterprise Management (WMI), not likely needed in Cygwin "/DOS/c/WINDOWS/System32/Wbem", ); my %DUP = (); my @Path = split /:/, $ENV{PATH}; my @NewPath = (); for my $dir (@Path) { if (! -d $dir) { print STDERR "MISSING: $dir\n" if $DBG; } elsif (exists $IGNORE{lc $dir}) { ++$IGNORE{$dir}; print STDERR "IGNORED: $dir\n" if $DBG; } elsif (exists $DUP{lc $dir}) { print STDERR "DUP: $dir\n" if $DBG; ++$DUP{lc $dir}; } else { print STDERR "ADDED: $dir\n" if $DBG; $DUP{lc $dir}=0; push @NewPath, $dir; } } # Output the new PATH variable print join(":", @NewPath);