Created
April 25, 2014 02:32
-
-
Save syohex/11276140 to your computer and use it in GitHub Desktop.
remove dead directories from cdr list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use File::Spec; | |
my $file = File::Spec->catfile($ENV{HOME}, ".chpwd-recent-dirs"); | |
open my $fh, '<', $file or die "Can't open file $!"; | |
my @lives; | |
while (my $line = <$fh>) { | |
chomp $line; | |
if ($line =~ m{\A\$'(.+)'\z}) { | |
my $dir = $1; | |
unless (-d $dir) { | |
print "$dir is no longer existed\n"; | |
next; | |
} | |
push @lives, $line; | |
} | |
} | |
close $fh; | |
open my $wfh, '>', $file or die "Can't open file $!"; | |
print {$wfh} join("\n", @lives); | |
print {$wfh} "\n"; | |
close $wfh; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment