-
Notifications
You must be signed in to change notification settings - Fork 0
/
vim_swap.pl
executable file
·47 lines (43 loc) · 1.05 KB
/
vim_swap.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl -w
# Courtesy : John Orr <[email protected]> posted on vim mailing list.
use strict;
my $v = 'vim -f';
my $vd = 'vim -d -f';
my $dir = '.';
if (scalar @ARGV)
{
$dir = $ARGV[0];
}
my $cmd = "find $dir -maxdepth 1 -name '.*.sw*'";
# my $cmd = "find $dir -name '.*.sw*'";
my @files=`$cmd`;
foreach my $file (@files)
{
my $filepath;
my $filename;
my $newfile;
my $oldfile;
chomp $file;
if ($file =~ /^(.*)\/\.(.*)\.sw.$/)
{
$filepath = $1;
$filename = $2;
$oldfile = "$filepath/$filename";
$newfile = $filepath . "/new_" . $filename;
$cmd = "$v -r $file -c 'write $newfile|quit'";
print "$cmd\n";
system($cmd);
unlink "$file";
if (system("diff '".$oldfile."' '".$newfile."'"))
{
# Files differ
print "'$oldfile' differs from '$newfile'\n";
system("$vd '$oldfile' '$newfile'");
}
else
{
print "'$oldfile' not changed\n";
unlink "$newfile";
}
}
}