]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
Improved wildcard matching
authormartin f. krafft <redacted>
Thu, 9 Sep 2021 23:27:37 +0000 (01:27 +0200)
committermartin f. krafft <redacted>
Sat, 11 Sep 2021 06:02:06 +0000 (08:02 +0200)
No reason why '*' cannot appear as part of a word, e.g. 'debian-*', so
let's implement that.

Signed-off-by: martin f. krafft <redacted>
scripts/ctrlact.pl

index 74464f2239691d9da6d859ccaa17f648b0fe67e1..19b6c2392d218f945de9345e5271c81d0a10b39b 100644 (file)
@@ -46,8 +46,8 @@
 #
 # Note that the name is either matched in full and verbatim, or treated like
 # a regular expression, if it starts and ends with the same punctuation
-# character. The asterisk ('*') is special and simply gets translated to /.*/
-# internally. No other wildcards are supported.
+# character. You may also use the asterisk by itself to match everything, or
+# as part of a word, e.g. #debian-*. No other wildcards are supported.
 #
 # Once you defined your mappings, please don't forget to /ctrlact reload them.
 # You can then use the following commands from Irssi to check out the result:
@@ -207,14 +207,15 @@ my @query_thresholds;
 
 sub match {
        my ($pat, $text) = @_;
-       my $npat = ($pat eq '*') ? '/.*/' : $pat;
-       if ($npat =~ m/^(\W)(.+)\1$/) {
-               my $re = qr/$2/;
-               $pat = $2 unless $pat eq '*';
-               return $pat if $text =~ /$re/i;
+       if ($pat =~ m/^(\W)(.+)\1$/) {
+               return $pat if $text =~ /$2/i;
+       }
+       elsif ($pat =~ m/\*/) {
+               my $rpat = $pat =~ s/\*/.*/gr;
+               return $pat if $text =~ /$rpat/
        }
        else {
-               return $pat if lc($text) eq lc($npat);
+               return $pat if lc($text) eq lc($pat);
        }
        return 0;
 }
git clone https://git.99rst.org/PROJECT