-
-
Notifications
You must be signed in to change notification settings - Fork 57
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 against specific keys #486
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Jean Mertz <[email protected]>
After adding some more complex rules, I've determined that my mental model of the relationships between categories and rules was off. I assumed that a single category could have zero or more rules attached, but in fact it can only have zero or one. This means that my key/value-based rule is too limiting for more complex set-ups. For example, if I have a category "Chat", and I want for it to include the With the current architecture (one rule per category), you'd want to have a higher-level rule that "groups" other rules together. For example, you would have an That way, you could express my above example as:
In this case, the single For the server, I don't see any hurdles to implementing this, it's fairly straightforward and mostly the same as what I did with I'll probably add the |
Signed-off-by: Jean Mertz <[email protected]>
Alright, I've pushed a change in Here is one example of my current set-up: [
{
"id": 23,
"name": [
"Productivity"
],
"rule": {
"type": "or",
"rules": [
{
"type": "keyvalue",
"rules": {
"app": {
"type": "regex",
"regex": "^Shortcuts|Fantastical Helper$"
}
}
},
{
"type": "keyvalue",
"rules": {
"title": {
"type": "regex",
"regex": "^Fantastical$"
}
}
}
]
}
}
] |
Signed-off-by: Jean Mertz <[email protected]>
8a560fa
to
d83de8a
Compare
I realized that a small (backward-compatible) tweak to the With the latest change, there is now an optional field [
{
"id": 22,
"name": [
"Video"
],
"rule": {
"type": "and",
"rules": [
{
"type": "regex",
"field": "app",
"regex": "^Safari$"
},
{
"type": "regex",
"field": "title",
"regex": "YouTube$"
}
]
}
},
{
"id": 23,
"name": [
"Productivity"
],
"rule": {
"type": "or",
"rules": [
{
"type": "regex",
"field": "app",
"regex": "^Shortcuts|Fantastical Helper$"
},
{
"type": "regex",
"field": "title",
"regex": "^Fantastical$"
}
]
}
}
] |
edit: See latest comment for the updated design.
I made a small change to the server, to support regex-matching against specific labels in the event.
For example, on macOS, Messages.app's window title consists only of the name of the contact. Matching against "John Doe" with the default
regex
rule would match either theapp
ortitle
label, which would be insufficient, as it would also match other apps for which the title contains "John Doe".With this new
KeyValue
rule, you can now specifically define in which field the value is expected to match.For the above example, the following change is made to the configuration JSON:
Specifically,
rule.type
is changed fromregex
tokeyvalue
andrule.regex
is changed torule.rules
which is a list of objects, for which the key is the name of the field you want to match against, and the value is a rule object (so in the future, this could support glob rules as well).Note that I'm adding these rules directly in the SQLite database, I did not update the UI, so that'll have to be tackled by someone else if this is deemed worthy of including in a future release.
There are also no tests, currently. I'm willing to add those, but it might take a few days/weeks before I get to that. This was mainly a quick change to scratch an itch I had, and I wanted to push this up to see if this can land in an official release in the future.