Skip to content

Instantly share code, notes, and snippets.

@soh335
Created December 25, 2011 10:59
Show Gist options
  • Save soh335/1519096 to your computer and use it in GitHub Desktop.
Save soh335/1519096 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use IPC::Cmd qw/run_forked/;
use Cocoa::Growl ':all';
use Filesys::Notify::Simple;
$| = 1;
growl_register(
app => "tex watcher",
notifications => [qw/error warning notify/],
);
my @commands = (
"uplatex-utf8 -interaction=nonstopmode main.tex",
"jbibtex main",
"uplatex-utf8 -interaction=nonstopmode main.tex",
"dvipdfmx main.dvi",
);
my $print_handle = sub {
my $line = shift;
if ( $line =~ /^! / ) {
growl_notify(
name => "error",
title => "error",
description => $line,
);
}
elsif ( $line =~ /^Warning/ ) {
growl_notify(
name => "warning",
title => "warning",
description => $line,
);
}
print $line;
};
my $watcher = Filesys::Notify::Simple->new( [ $FindBin::Bin ] );
while (1) {
$watcher->wait(sub {
my @res = grep { $_->{path} =~ /\.(tex|bib)$/ } @_;
return unless @res;
my $res = run_forked(
join("&&", @commands),
{
stderr_handler => $print_handle,
stdout_handler => $print_handle,
}
);
if ( $res->{exit_code} == 0 ) {
growl_notify(
name => "notify",
title => "compile success",
);
}
else {
growl_notify(
name => "error",
title => "compile error",
);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment