]> Sergey Matveev's repositories - zk.git/commitdiff
.zkignore
authorSergey Matveev <stargrave@stargrave.org>
Thu, 8 May 2025 14:04:24 +0000 (17:04 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 8 May 2025 15:05:15 +0000 (18:05 +0300)
zk

diff --git a/zk b/zk
index 45801f44addc67ab439ee944a6d420023d1af9f6..de3dd4594ca51d3da7ffb37d4e6a4cf7fe9f7391 100755 (executable)
--- a/zk
+++ b/zk
@@ -103,6 +103,12 @@ HTML output. Set C<ZK_DO_BACKS=0> to disable automatic backlinks-table.
 If C<do-links\r> line is presented, then links-table is forcefully generated.
 C<do-backs\r> generated backlinks table.
 
+=head1 IGNORED FILES
+
+You can ignore specified files processing by placing regular expressions
+on separate lines in .zkignore file. They are applied to full relative
+path of walked files.
+
 =head1 HISTORY
 
 Older version of that script, written on Z shell, can be found in Git history.
@@ -134,13 +140,31 @@ my %sizes;
 my %cats;
 
 {
+    my @ignores;
+    if (-e ".zkignore") {
+        open my $fh, "<", ".zkignore" or die "$!";
+        while (<$fh>) {
+            chop;
+            push @ignores, $_;
+        }
+        close $fh;
+    }
+    sub isignored {
+        my $p = shift;
+        foreach my $re (@ignores) {
+            return 1 if $p =~ m/$re/;
+        }
+        return 0;
+    }
     use File::Find;
     use POSIX qw(strftime);
     sub wanted {
         my $fn = $_;
+        return if $fn =~ /^\./;
         my $pth = $File::Find::name;
         $pth =~ s/^\.\/?//;
         if (-d $fn) {
+            return if isignored "$pth/";
             opendir(my $dh, $fn) or die "$!";
             my @entries;
             while (readdir $dh) {
@@ -148,11 +172,13 @@ my %cats;
                 if (-d "$fn/$_") {
                     $_ .= "/";
                 }
+                next if isignored(($fn eq ".") ? $_ : "$fn/$_");
                 push @entries, $_;
             }
             closedir $dh;
             $cats{$pth} = \@entries;
         } else {
+            return if isignored $pth;
             my @s = stat($fn) or die "$!";
             $sizes{$pth} = $s[7];
             $mtimes{$pth} = strftime "%Y-%m-%d %H:%M:%S", gmtime $s[9];