Button visibility determined by the result of a script

General question: Is there a more complicated way to determine visibility of button or icon on status bar than operating on current directory contents and selected files/dirs? Is there some example how to achieve that?

Precise question: I would like to have a button (also maybe an icon on status bar below lister) that is visible only if current directory or any directory above it contains specified directory or file. For example:
C:\ - doesn't contain ".git" directory - icon/button is not there
C:\repos - contains ".git" directory - icon/button is visible
C:\repos\project 1 - no ".git" directory here but parent directory had it - icon/button is visible
C:\repos\project 1\resources - as above - icon/button is visible
I know that determining visibility only on existing files/dirs in current directory can be easily achieved but this is something more complicated than that as the logic goes beyond current directory.

The status bar has an {ifexists:...} code which can check if a specified path exists. But it only lets you use a path relative to the current dir or an absolute path, so it would be able to check for .git in a specific place or .git below the current folder, but it wouldn't find .git in the parent folder.

(At least without lots of checks for each possible parent level relative to the current dir, up to some limit, but that would be quite messy and probably a little slow as well.)

If all your git repos are below C:\repos then you could just have the buttons/icons appear when in or below C:\repos, which is easily doable.

Okay it seems that it won't do for the status bar. Status bar has also little (none?) API read/write access to manipulate it on the fly.
Narrowing this question down to button only, though: maybe I could create a script that reacts on "OnAfterFolderChange" to achieve that? I see AfterFolderChangeData provides me Path (which I can lean my predicate on) and Tab... which has Lister... which has Toolbars. Maybe that way I could switch visibility of known button(s)?

You could probably use a script on that event, and set a variable on the file display, which can be checked by the status bar.

Oh, I see. That could work.
Just to make sure: how a variable turns boolean when used with:
Do I have to set it's value to "true"/"false" or "on"/"off"?

Outside of scripting, checks on variables are usually simply "does it exist or not". So you'd set it to something (doesn't matter what) to turn it on, and delete it entirely to turn it off.