Open gafinan opened 2 years ago
#
#
#
#
use strict; use Getopt::Std; use File::Spec::Unix;
our (%opts); # hash to store command-line switches getopts( 'bis', \%opts);
my $background = "false"; my $case_sensitive = "true"; my $ignore_whitespace = "false"; if ($opts{'b'}) { $background = "true"; } if ($opts{'i'}) { $case_sensitive = "false"; } if ($opts{'s'}) { $ignore_whitespace = "true"; }
my $count = @ARGV; if ($count != 2) { die usage(); }
my ($old_file, $new_file) = @ARGV; $new_file = File::Spec::Unix->rel2abs( $new_file ); $old_file = File::Spec::Unix->rel2abs( $old_file );
foreach ($old_file, $newfile) { ( -f ) or die $ . " is not a file.\n"; }
my $comp_script = qq[ tell application "BBEdit" set comp_opts to {case sensitive:$case_sensitive, ignore leading spaces:$ignore_whitespace, ignore trailing spaces:$ignore_whitespace} set comp_result to compare POSIX file "$new_file" against POSIX file "$old_file" options comp_opts if differences found of comp_result then if not $background then activate return "Differences found." else set the_reason to reason for no differences of comp_result return "No differences found: " & the_reason end if end tell ];
system ( "/usr/bin/osascript -e '$comp_script'" );
sub usage { die << "ENDUSAGE"; Usage: $0 [-b -i -s] oldfile newfile -b keep BBEdit in the background -i case insensitive comparison -s ignore leading and trailing whitespace on lines
ENDUSAGE }
END
=pod
=head1 NAME
B
=head1 SYNOPSIS
bbdiff [-b -i -s] oldfile newfile
=head1 OPTIONS
B
=over 4
=item B<-b>
Keep BBEdit in the background. By default, BBEdit will activate if differences are found.
=item B<-i>
Case insensitive comparison.
=item B<-s>
Ignore leading and trailing whitespace on lines.
=back
=head1 VERSION HISTORY
1.0: Sat Nov 30, 2002
Initial release.
1.1: Wed Dec 4, 2002
Swapped order of oldfile and newfile in argument list, to match usage
of existing diff tools.
Convert arguments to full paths before testing whether the files exist.
=head1 AUTHOR
John Gruber
http://daringfireball.net/projects/bbdiff/
=head1 COPYRIGHT and LICENSE
Copyright (c) 2002 John Gruber.
This program is free and open software. You may use, copy, modify, distribute, and sell this program (and any modified variants) in any way you wish, provided you do not restrict others from doing the same.
=cut
https://github.com/gafinan/gafinan/blob/main/README.md And then