#!/usr/bin/perl

=head1 NAME

reswatch - Restart Swatch

=head1 DESCRIPTION

B<Reswatch> attempts to send a HUP signal to a swatch process. It finds the 
process ID of B<swatch> by looking for a file named I<.swatch_script.>B<PID>
in the home directory.

=head1 SEE ALSO

b<swatch(1)>

=cut

use DirHandle;

my $script_prefix = '.swatch_script';
my $homedir = $ENV{'HOME'};
my $dh = new DirHandle $homedir;

if (defined $dh) {
  while (defined($_ = $dh->read)) {
    if (/^${script_prefix}\.[0-9]*/) {
      split(/\./, $_);;
      print "Sending HUP signal to PID $_[$#_]\n";
      kill('HUP', $_[$#_]);
      undef $dh;
      exit 0;
    }
  }
}
undef $dh;
exit 1;
