rlm@6: #!/usr/bin/perl rlm@6: rlm@6: use Linux::Inotify2; rlm@11: use WWW::Mechanize::Firefox; rlm@11: my $mech = WWW::Mechanize::Firefox->new(); rlm@6: rlm@6: my $inotify = new Linux::Inotify2 rlm@6: or die "unable to create new inotify object: $!"; rlm@6: rlm@6: rlm@16: $org_files = `find /home/r/proj -name "*.org" -print0`; rlm@16: @org_files = split /\0/, $org_files; rlm@6: rlm@16: #@org_files = glob("./org/*.org"); rlm@16: rlm@16: for $file(@org_files){print "$file\n";} rlm@9: $ignore_next = 0; rlm@17: $last_page = ""; rlm@6: rlm@6: foreach(@org_files){ rlm@6: # add watchers rlm@6: $inotify->watch ($_, IN_MODIFY, sub rlm@6: { rlm@9: print ("IGNORE : $ignore_next\n"); rlm@15: # ok, for some reason this gets called exactly rlm@9: # twice every time the file is saved from emacs. rlm@9: # so ignore every other invocation. rlm@9: if ($ignore_next) { rlm@9: $ignore_next = 0; rlm@9: return; rlm@9: } rlm@13: $ignore_next = 1; rlm@9: rlm@9: my $e = shift; rlm@9: my $name = $e->fullname; rlm@9: print "$name was modified\n" if $e->IN_MODIFY; rlm@9: $output = `weave $name`; rlm@9: $path = `readlink -f $name`; rlm@9: $path =~ s|/home/r/proj|http://aurellem.localhost|; rlm@9: $path =~ s|org|html|g; rlm@17: if ($last_page eq $path){ rlm@17: print "reloading current page : $path\n"; rlm@17: $mech->reload(); rlm@17: } rlm@17: else { rlm@17: print "moving to new page : $path\n"; rlm@17: $last_page = $path; rlm@17: $mech->get($path); rlm@17: } rlm@6: }); rlm@6: } rlm@6: rlm@6: rlm@13: # manual event loop rlm@6: 1 while $inotify->poll;