elkowar / eww

ElKowars wacky widgets
https://elkowar.github.io/eww
MIT License
9.36k stars 382 forks source link

[FEATURE] Export magic variables to env for script execution #1165

Open MartyMcFlyInTheSky opened 2 months ago

MartyMcFlyInTheSky commented 2 months ago

Description of the requested feature

When executing a script from yuck, e.g.


(button :active {loading == false}
                    :class "spinner"
                    :onclick "python scripts/load_networks.py"
                    "${ spinner_symbol }")

populate its environment with the magic variables beforehand so the script can make use of them. E.g. in my python script I want to do the following:

eww_cmd: str = os.getenv('EWW_CMD')

...

    proc = await asyncio.create_subprocess_shell(f'{eww_cmd} update {vars}',
        stdout=asyncio.subprocess.PIPE,
        stderr=asyncio.subprocess.PIPE)

This will allow to guard against cases where eww is invoked with a specific configuration file (eww --config ...) as described in the docs (if I understood correctly this is why the ${EWW_CMD} variable exists in yuck?).

Proposed configuration syntax

internal

Additional context

No response

ovalkonia commented 2 months ago

Why not just pass all the needed data as command line arguments?

MartyMcFlyInTheSky commented 2 months ago

I mean sure, but also why not have them as environmental variables? It would decrease the verbosity and make it more clean imho. As a user I was also quite surprised that this doesn't work, which goes against the principle of least astonishment.

ovalkonia commented 2 months ago

Fair enough. As it turns out, there's not way to access variables in defvar, defpoll and deflisten, so there is no way to pass them now. If we were able to do that, we could just pass the needed variables as command line arguments or just set the environmental variables ourselves. Having all magic variables set by default at all times seems kind of excessive, you realistically need one or two. Maybe the access to variables in defvar can be made possible

MartyMcFlyInTheSky commented 2 months ago

Yes that should be supported at least. Even though I think that exporting 10 variables is not all that excessive, one could export just a subset. I mean for the other variables it might not even make sense to be exported, but EWW_CMD has a real use case.