aboutsummaryrefslogtreecommitdiffstats
path: root/git-update-changed-param-hook
blob: 0407e2966552487db391cc5b0c5744bb40489dd1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env perl

# -*- mode: cperl -*-


use strict;
use warnings;
use File::Spec;
use feature qw/say/;

my $file_cmd = "/usr/bin/file";
my $git_cmd = "/opt/local/bin/git";

my $root_dir = qx/$git_cmd rev-parse --show-toplevel/;
chomp ($root_dir);

my @changed_files = qx/git status --porcelain -u no/;

foreach my $file (@changed_files) {
    chomp $file;
    if (is_irssi_script($file)) {
        system(File::Spec->catfile($root_dir, 'changed_update.pl'), $file);
    }
}


sub is_irssi_script {
    my ($file) = @_;
    my $full_path = File::Spec->catfile($root_dir, $file);
    return 0 unless -f $full_path;
    my $file_result = system("/usr/bin/grep -s -q '\%IRSSI' 1>/dev/null 2>&1");
    if ($file_result != 0) {
        return 0;
    } else {
        return 1;
    }
}