rlm@6
|
1 #!/usr/bin/perl
|
rlm@6
|
2
|
rlm@6
|
3 use Linux::Inotify2;
|
rlm@11
|
4 use WWW::Mechanize::Firefox;
|
rlm@11
|
5 my $mech = WWW::Mechanize::Firefox->new();
|
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@16
|
11 $org_files = `find /home/r/proj -name "*.org" -print0`;
|
rlm@16
|
12 @org_files = split /\0/, $org_files;
|
rlm@6
|
13
|
rlm@16
|
14 #@org_files = glob("./org/*.org");
|
rlm@16
|
15
|
rlm@16
|
16 for $file(@org_files){print "$file\n";}
|
rlm@9
|
17 $ignore_next = 0;
|
rlm@17
|
18 $last_page = "";
|
rlm@6
|
19
|
rlm@6
|
20 foreach(@org_files){
|
rlm@6
|
21 # add watchers
|
rlm@6
|
22 $inotify->watch ($_, IN_MODIFY, sub
|
rlm@6
|
23 {
|
rlm@9
|
24 print ("IGNORE : $ignore_next\n");
|
rlm@15
|
25 # ok, for some reason this gets called exactly
|
rlm@9
|
26 # twice every time the file is saved from emacs.
|
rlm@9
|
27 # so ignore every other invocation.
|
rlm@9
|
28 if ($ignore_next) {
|
rlm@9
|
29 $ignore_next = 0;
|
rlm@9
|
30 return;
|
rlm@9
|
31 }
|
rlm@13
|
32 $ignore_next = 1;
|
rlm@9
|
33
|
rlm@9
|
34 my $e = shift;
|
rlm@9
|
35 my $name = $e->fullname;
|
rlm@9
|
36 print "$name was modified\n" if $e->IN_MODIFY;
|
rlm@9
|
37 $output = `weave $name`;
|
rlm@9
|
38 $path = `readlink -f $name`;
|
rlm@9
|
39 $path =~ s|/home/r/proj|http://aurellem.localhost|;
|
rlm@9
|
40 $path =~ s|org|html|g;
|
rlm@17
|
41 if ($last_page eq $path){
|
rlm@17
|
42 print "reloading current page : $path\n";
|
rlm@17
|
43 $mech->reload();
|
rlm@17
|
44 }
|
rlm@17
|
45 else {
|
rlm@17
|
46 print "moving to new page : $path\n";
|
rlm@17
|
47 $last_page = $path;
|
rlm@17
|
48 $mech->get($path);
|
rlm@17
|
49 }
|
rlm@6
|
50 });
|
rlm@6
|
51 }
|
rlm@6
|
52
|
rlm@6
|
53
|
rlm@13
|
54 # manual event loop
|
rlm@6
|
55 1 while $inotify->poll;
|