-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathdiffin
More file actions
executable file
·39 lines (30 loc) · 758 Bytes
/
diffin
File metadata and controls
executable file
·39 lines (30 loc) · 758 Bytes
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
#!/usr/bin/perl
#
# diff two or more buffers
# split buffers with an empty line (\n) or end STDIN multiple times (ctrl+d per buffer)
# -samy kamkar 2020/11/08
# https://samy.pl
use strict;
my $FILE = "/tmp/.diff.buf.";
my $DIFF = 'colordiff';
my @OPTS = qw/-btwur/;
my @buf;
# read in buffers until we have an empty one
do
{
push @buf, join "", <STDIN>;
print STDERR "read in buffer\r";
} while $buf[-1] ne "";
print "-" x 60, "\n";
# last is empty
pop @buf;
# if we only have one, treat empty lines as delimmeters
splice(@buf, 0, 1, split(/\n\n/, $buf[0])) if @buf == 1;
# last buff is empty
for my $i (1 .. @buf)
{
open(OUT, ">$FILE$i");
print OUT $buf[$i-1];
close(OUT);
system($DIFF, @OPTS, $FILE . ($i-1), $FILE . $i) if $i != 1;
}