From 0727ad7dd4a19c8473a7caa573620b9fe31dbcc6 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 8 May 2025 17:04:24 +0300 Subject: [PATCH] .zkignore --- zk | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/zk b/zk index 45801f4..de3dd45 100755 --- a/zk +++ b/zk @@ -103,6 +103,12 @@ HTML output. Set C to disable automatic backlinks-table. If C line is presented, then links-table is forcefully generated. C 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]; -- 2.48.1