Mercurial > org-tools
view auto-weave.pl @ 11:24ff8a9c76c4
all day for three lines
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 25 Oct 2011 08:00:48 -0700 |
parents | d09937a6cb4b |
children | be73e58d4b24 |
line wrap: on
line source
1 #!/usr/bin/perl3 use Linux::Inotify2;4 use WWW::Mechanize::Firefox;5 my $mech = WWW::Mechanize::Firefox->new();7 my $inotify = new Linux::Inotify28 or die "unable to create new inotify object: $!";11 @org_files = glob("./org/*.org");13 $" = "\n";14 print "@org_files\n";16 $ignore_next = 0;19 foreach(@org_files){20 # add watchers21 $inotify->watch ($_, IN_MODIFY, sub22 {23 print ("IGNORE : $ignore_next\n");24 # ok, for some reason this get's called exactly25 # twice every time the file is saved from emacs.26 # so ignore every other invocation.27 if ($ignore_next) {28 $ignore_next = 0;29 return;30 }32 my $e = shift;33 my $name = $e->fullname;34 print "$name was modified\n" if $e->IN_MODIFY;35 $output = `weave $name`;36 print ("$name\n");37 $path = `readlink -f $name`;38 $path =~ s|/home/r/proj|http://aurellem.localhost|;39 print ("$path\n");40 $path =~ s|org|html|g;41 print ("$path\n");42 #system ("firefox $path");43 $mech->get($path);44 $ignore_next = 1;46 });47 }52 # integration into AnyEvent (works with EV, Glib, Tk, POE...)53 #my $inotify_w = AnyEvent->io54 # (55 # fh => $inotify->fileno, poll => 'r', cb => sub { $inotify->poll }56 # );58 # manual event loop59 1 while $inotify->poll;