Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support regex matching in rules #1013

Closed
levouh opened this issue Jan 12, 2022 · 16 comments · Fixed by #1017
Closed

Support regex matching in rules #1013

levouh opened this issue Jan 12, 2022 · 16 comments · Fixed by #1017

Comments

@levouh
Copy link

levouh commented Jan 12, 2022

Is there a better way to ignore things based on summary for a given appname (yes I am aware that I should use desktop_entry instead) than:

[kdec_pushover_ignore]
    appname = "KDE Connect"
    summary = "Pushover"
    format = ""

[kdec_gmail_ignore]
    appname = "KDE Connect"
    summary = "Gmail"
    format = ""

[kdec_cal_ignore]
    appname = "KDE Connect"
    summary = "Calendar"
    format = ""

[kdec_ov_ignore]
    appname = "KDE Connect"
    summary = "Okta Verify"
    format = ""

For example, using a script based on the appname that just modifies the format like:

[kdec_ignore]
    appname = "KDE Connect"
    summary = "*"
    script = ignore.sh

where the script can use "better" pattern matching (basically just a bunch of | statements) and "return" format = "" (to ignore the notification) manually?

@fwsmit
Copy link
Member

fwsmit commented Jan 12, 2022

You cannot use a script to do this, but you should be able to do it the way you suggest inside of dunst. Dunst uses fnmatch(3) for pattern matching a list of patterns. The pattern: summary = @(one|two|three)" matches any string that contains "one", "two" or "three".

This should probably get documented better, but I hope this answers your question.

@levouh
Copy link
Author

levouh commented Jan 12, 2022

Definitely does, thanks.

@levouh levouh closed this as completed Jan 12, 2022
@levouh
Copy link
Author

levouh commented Jan 12, 2022

@fwsmit Given that my notifications are coming through as:

appname=KDE Connect
summary=Gmail

which is captured using a script to just log every notification (skipping something like running dunst with -print mostly just to check the rule is happening), my rule is:

[kdec_ignore]
    appname = "KDE Connect"
    summary = "@(Pushover|Gmail|Calendar)"
    format = ""

and things are not being ignored as I would expect. Is the format there correct? I will modify the "logging" to check trailing whitespace, but I would expect these to be ignored.

I run dunst as a user service, and am restarting it to reload the configuration via systemctl --user restart dunst. I have also verified that once I kill it, there are no other instances running (and it is loading my other configuration so I know the configuration file is being read).

@fwsmit
Copy link
Member

fwsmit commented Jan 12, 2022

Whoops, read the fnmatch documentation incorrectly. Dunst calls fnmatch without flags, but you need the FNM_EXTMATCH flag to have the behavior. It's a gnu extension, so I'll have to look to see how we can enable it on certain platforms.

@fwsmit fwsmit reopened this Jan 12, 2022
@levouh levouh changed the title [Question] Better way to do ignores based on summary Support fnmatch expressions by enabling FNM_EXTMATCH Jan 12, 2022
@fwsmit
Copy link
Member

fwsmit commented Jan 15, 2022

Looking into this, I found this PR: #659, which implements said feature, but it was decided it was not the right solution. Regex was deemed as the more correct solution. I'll look into how that could be implemented right now. I'll make a tracking issue to consolidate the different issues about this.

@levouh
Copy link
Author

levouh commented Jan 15, 2022

Sounds good, want me to close this one?

For what its worth, being able to filter using a script (perhaps return an exit code) could also be relatively agnostic to how the user wants to do it. Could be (potentially) less work on the dunst side?

@fwsmit
Copy link
Member

fwsmit commented Jan 15, 2022

Sounds good, want me to close this one?

No, you can keep this open. I'll close it when regex is implemented.

For what its worth, being able to filter using a script (perhaps return an exit code) could also be relatively agnostic to how the user wants to do it. Could be (potentially) less work on the dunst side?

That's a possibility, but it would be easier for the user to use regex of course. For more advanced use cases which will never be supported by dunst this would be an option.

fwsmit added a commit to fwsmit/dunst that referenced this issue Jan 15, 2022
This enables more advanced regular expression syntax. It can be enabled
with `enable_posix_regex`.

Fixes: dunst-project#1013
Fixes: dunst-project#645
Fixes: dunst-project#658
@fwsmit
Copy link
Member

fwsmit commented Jan 15, 2022

@levouh I've implemented regex in #1017. Would you mind testing it?

@levouh
Copy link
Author

levouh commented Jan 15, 2022

Will do!

fwsmit added a commit to fwsmit/dunst that referenced this issue Jan 15, 2022
This enables more advanced regular expression syntax. It can be enabled
with `enable_posix_regex`.

Fixes: dunst-project#1013
Fixes: dunst-project#645
Fixes: dunst-project#658
@levouh levouh changed the title Support fnmatch expressions by enabling FNM_EXTMATCH Support regex matching in rules Jan 15, 2022
@levouh
Copy link
Author

levouh commented Jan 15, 2022

@fwsmit it would look something like:

[kdec_ignore]
    appname = "KDE Connect"
    summary = "Gmail|Slack"
    format = ""

and not:

[kdec_ignore]
    appname = "KDE Connect"
    summary = "Gmail\|Slack"
    format = ""

right?

@levouh
Copy link
Author

levouh commented Jan 15, 2022

Actually looks like the commit has docs, let me read those.

@fwsmit
Copy link
Member

fwsmit commented Jan 15, 2022

@fwsmit it would look something like:

[kdec_ignore]
    appname = "KDE Connect"
    summary = "Gmail|Slack"
    format = ""

and not:

[kdec_ignore]
    appname = "KDE Connect"
    summary = "Gmail\|Slack"
    format = ""

right?

yes

Actually looks like the commit has docs, let me read those.

also yes :)

@fwsmit
Copy link
Member

fwsmit commented Jan 15, 2022

I opted for the extended syntax, as I don't think you will often need to match the special characters literally.

@levouh
Copy link
Author

levouh commented Jan 15, 2022

Works perfectly for me, tried a handful of regex things like [], [^], .*, etc.

Also verified that the old syntax for * replaced with .* works as intended.

Thanks for the feature!

@fwsmit
Copy link
Member

fwsmit commented Jan 15, 2022

Works perfectly for me, tried a handful of regex things like [], [^], .*, etc.

Also verified that the old syntax for * replaced with .* works as intended.

Thanks for the feature!

Cool. I'll add error messages for incorrect regex patterns and then I'll merge it.

fwsmit added a commit to fwsmit/dunst that referenced this issue Jan 16, 2022
This enables more advanced regular expression syntax. It can be enabled
with `enable_posix_regex`.

Fixes: dunst-project#1013
Fixes: dunst-project#645
Fixes: dunst-project#658
@fwsmit
Copy link
Member

fwsmit commented Jan 16, 2022

Merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants