phuhl / linux_notification_center

A notification daemon/center for linux
BSD 3-Clause "New" or "Revised" License
1.01k stars 40 forks source link

Scrippting match patterns #192

Closed kristianvld closed 1 year ago

kristianvld commented 2 years ago

It would be really nice to be able to match patterns and not only exact values.

For instance, being able to match any notifications with a word in the title or body would be nice. Either with simple pattern like

match = "title=*black*" # match any title containing the word black
...
match = "title=*black" # match any title ending in the word black
...
match = "title=/[0-9a-f]{16} black/i" # regex, match titles starting with a 16 digit hex number and ending in black, ignore case
...
match = "title=*" # matches all notifications

This on it's own could be really powerful, but even more so when #138 gets implemented.

The last example would also be a nice way to match any notifications. Currently I don't see any way to do this, even though I would expect an empty match to do this (as all [none] match conditions are met).

phuhl commented 2 years ago

Not entirely sure, but I think in https://github.com/phuhl/linux_notification_center/pull/138 you can match everything by having an empty match.

Then you could use the scripting method to match however you like in a script and only modify when you match, using this: image

Btw, you can test what is in https://github.com/phuhl/linux_notification_center/pull/138 as of today. The code is there. The only reason it is not merged, yet, is because it has a lot of braking changes regarding configuration. But one day, when I feel brave, I probably will merge.

If you try that, I'd love to hear your feedback on how it went

phuhl commented 1 year ago

Should be fixed by new config format

TIAcode commented 3 months ago

I don't think matching all works? Without any match: deadd-notification-center: AesonException "Error in $.modifications[7]: key \"match\" not found" Empty match block" deadd-notification-center: AesonException "Error in $.modifications[7].match: parsing Map failed, expected Object, but encountered Null" And matching with an empty filter string doesn't match anything.

phuhl commented 3 months ago

What is your config?

TIAcode commented 3 months ago

All right, apparently I didn't know how to define empty Maps in yaml, your question made me question my own knowledge and I found a solution. If anyone else is looking for it

  modifications:
    - match: {}
      script: "/home/santzes/.config/qtile/notifications/processor/process_notification.py"

seems to match everything. Thanks