filesortd icon indicating copy to clipboard operation
filesortd copied to clipboard

Conditional matchers #discussion

Open goshacmd opened this issue 12 years ago • 4 comments

Hazel has some really powerful features, among them is the ability to run matchers + conditional.

A real-world example: I might want to perform some action on either items labeled greed or items ending in .dmg

I think we might do something like this with match:

match :or, { set1: true }, { set2: true }, &callback

So that, callback gets executed in case matchers set1 or set2 return truth.

Then, we could also have some sort of nested matchers:

match :or, [:or, { set1: true, set2: true }], { set3: true, set4: true }, &callback

By default, if no condition is specified, it is assumed to be :all. So both of the following are equal:

match :and, { set1: true }, { set2: true }

match set1: true, set2: true

So how does it sounds?

goshacmd avatar Dec 17 '12 15:12 goshacmd

Maybe like this:

or {pattern: "*.rb"}, {kind: "Ruby Source"} do
end

valpackett avatar Dec 17 '12 15:12 valpackett

Okay, and what if I want it nested?

Maybe or/and should return the matcher object when passed no block so the following would work:

and or({pattern: '*.rb'}, {pattern: '*.pl'}), or({label: :gray}, {label: :none}) do
  # we have an either gray or non-labelled ruby or perl file
end

(I would only replace and/or with all/any then, because and/or are ruby's reserved words.)

goshacmd avatar Dec 17 '12 15:12 goshacmd

And on top of it, something like this could be implemented:

match label: [:gray, :none] do
  # stuff
end

In turn, match would make an or for each array item passed as matched param:

# so that equals to doing this
match or({label: :gray}, {label: :none}) do
  # stuff
end

goshacmd avatar Dec 17 '12 15:12 goshacmd

If you can implement this with clean code, do it :-)

valpackett avatar Dec 17 '12 16:12 valpackett