annotate auto-weave.pl @ 9:d09937a6cb4b

trying to build something to automatically refresh the browser.
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 05:33:36 -0700
parents 73beed20f7de
children 24ff8a9c76c4
rev   line source
rlm@6 1 #!/usr/bin/perl
rlm@6 2
rlm@6 3 use Linux::Inotify2;
rlm@6 4 use AnyEvent;
rlm@6 5
rlm@6 6
rlm@6 7 my $inotify = new Linux::Inotify2
rlm@6 8 or die "unable to create new inotify object: $!";
rlm@6 9
rlm@6 10
rlm@6 11 @org_files = glob("./org/*.org");
rlm@6 12
rlm@6 13 $" = "\n";
rlm@8 14 print "@org_files\n";
rlm@6 15
rlm@9 16 $ignore_next = 0;
rlm@9 17
rlm@6 18
rlm@6 19 foreach(@org_files){
rlm@6 20 # add watchers
rlm@6 21 $inotify->watch ($_, IN_MODIFY, sub
rlm@6 22 {
rlm@9 23 print ("IGNORE : $ignore_next\n");
rlm@9 24 # ok, for some reason this get's called exactly
rlm@9 25 # twice every time the file is saved from emacs.
rlm@9 26 # so ignore every other invocation.
rlm@9 27 if ($ignore_next) {
rlm@9 28 $ignore_next = 0;
rlm@9 29 return;
rlm@9 30 }
rlm@9 31
rlm@9 32 my $e = shift;
rlm@9 33 my $name = $e->fullname;
rlm@9 34 print "$name was modified\n" if $e->IN_MODIFY;
rlm@9 35 $output = `weave $name`;
rlm@9 36 print ("$name\n");
rlm@9 37 $path = `readlink -f $name`;
rlm@9 38 $path =~ s|/home/r/proj|http://aurellem.localhost|;
rlm@9 39 print ("$path\n");
rlm@9 40 $path =~ s|org|html|g;
rlm@9 41 print ("$path\n");
rlm@9 42 #system ("firefox $path");
rlm@9 43 $ignore_next = 1;
rlm@8 44
rlm@6 45 });
rlm@6 46 }
rlm@6 47
rlm@6 48
rlm@6 49
rlm@6 50
rlm@6 51 # integration into AnyEvent (works with EV, Glib, Tk, POE...)
rlm@8 52 #my $inotify_w = AnyEvent->io
rlm@8 53 # (
rlm@8 54 # fh => $inotify->fileno, poll => 'r', cb => sub { $inotify->poll }
rlm@8 55 # );
rlm@6 56
rlm@6 57 # manual event loop
rlm@6 58 1 while $inotify->poll;