Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
a script I use with claws-mail: https://bit.ly/2JJs5ql
#!/usr/bin/perl
use strict;
use warnings;
use File::Copy qw(copy);
#use X11::Protocol;
my $fname = $ARGV[0];
if(not defined $fname) {
die "No input\n";
}
my $dir = $ENV{"HOME"}."\/\.claws-mail\/my-custom-scripts\/tmp\/";
if (-d $dir) {
print "Directory $dir found. OK.\n";
} else {
print "Creating directory $dir.\n";
unless (mkdir $dir) {
die "Failed to create directory $dir.\n";
}
}
my $additions, my $deletions;
$additions = $dir."additions.txt";
$deletions = $dir."deletions.txt";
open(my $fh, '<', $fname) or die "Couldn't open file: $fname: $!\n";
open(my $fh_add, '>', $additions) or die "Couldn't open file $additions: $!\n";
open(my $fh_del, '>', $deletions) or die "Couldn't open file $deletions: $!\n";
while(!eof($fh)) {
defined(my $line = readline $fh) or die "Failed to read line.\n";
if ($line =~ m/^\+[^++]/) {
print $fh_add "$line";
print $fh_del "\n";
} elsif ($line =~m/^\-[^--]/) {
print $fh_add "\n";
print $fh_del "$line";
} else {
print $fh_add "$line";
print $fh_del "$line";
}
}
close($fh_del);
close($fh_add);
close($fh);
#my $x = X11::Protocol->new();
#print $x->{screens}->[0]->{width_in_pixels} .
# 'x' .
# $x->{screens}->[0]->{height_in_pixels} .
# "\n";
#my $w = 0.5 * $x->{screens}->[0]->{width_in_pixels};
#my $h = 0.5 * $x->{screens}->[0]->{height_in_pixels};
#my $geometry = "$w"."x"."$h"."+0+0";
my $command = qq[/usr/bin/icdiff --whole-file --cols=150 -H $deletions $additions | gvim - -c ":AnsiEsc" &];
system($command);
#my @cmd = ('/usr/bin/uxterm');
#push @cmd, '-geometry';
#push @cmd, $geometry;
#push @cmd, '-l';
#push @cmd, '-maximized';
#push @cmd, '-hold';
#push @cmd, '-e';
#push @cmd, $command;
#system(@cmd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.