Skip to content

Instantly share code, notes, and snippets.

@melo
Created September 12, 2012 15:53
Show Gist options
  • Save melo/3707617 to your computer and use it in GitHub Desktop.
Save melo/3707617 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
#
# Filesystem changes trigger
use v5.14;
use FindBin;
use lib "$FindBin::Bin/../lib";
use E1::Setup::Perl;
use Filesys::Notify::Simple;
$|++;
my ($dir, @cmd) = @ARGV;
die("FATAL: '$dir' is not a valid directory\n") unless -d $dir;
die("FATAL: need a command to run\n") unless @cmd;
my $watcher = Filesys::Notify::Simple->new([$dir]);
say "\n** Start waiting for changes to '$dir'";
$watcher->wait(
sub {
say "\n** Filesystem change detection:";
say " $_->{path}" for @_;
say "\n** Executing command:";
say " @cmd";
system(@cmd);
my $path = "$FindBin::Bin/../.release";
if (-f $path) {
my $now = time;
utime($now, $now, $path);
say "\n** Updated $path timestamp\n";
}
}
) while 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment