-
-
Save keiya/671860 to your computer and use it in GitHub Desktop.
remove the backup(swap) files of vim, gedit / usage: rmbf -d
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/perl | |
use strict; | |
use warnings; | |
use Cwd; | |
# rmbf version 1.0.1 | |
# Remove backup files | |
# Written by Keiya CHINEN | |
$| = 1; | |
if (defined $ARGV[0] and $ARGV[0] =~ /-d/) { | |
my $wd = Cwd::getcwd(); | |
print "Current directory: $wd\n\n"; | |
my $i = 0; | |
my @files; | |
opendir(DIR, "$wd"); | |
while (my $file = readdir(DIR)) { | |
if ($file =~ /~$/ or $file =~ /^\..+\.swp$/) { | |
$files[$i] = $file; | |
$i++; | |
print "Backup file found: $file\n"; | |
} | |
} | |
closedir(DIR); | |
if ($i > 1) { print "\nAre you sure want to remove these files? (y/n): " } | |
elsif ($i == 1) { print "\nAre you sure want to remove this file? (y/n): " } | |
else { | |
print "Backup file was not found.\n"; | |
exit; | |
} | |
my $yn; | |
read(STDIN,$yn,1); | |
if ($yn =~ /(?:^y$|^Y$)/) { | |
print "Removing..."; | |
if (unlink(@files) == $i) { | |
print "Succeed." | |
} else { | |
print "Failed." | |
} | |
} else { | |
print "Canceled."; | |
} | |
} else { | |
print <<__EOM__; | |
Usage: rmbf -d : Remove backup files in current directory. | |
-h / --help : Display this help message. | |
__EOM__ | |
} | |
print "\n" | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment