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

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

Open
MartyMcFlyInTheSky opened this issue Aug 23, 2024 · 4 comments
Open
Labels
enhancement New feature or request

Comments

@MartyMcFlyInTheSky
Copy link

MartyMcFlyInTheSky commented Aug 23, 2024

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

@MartyMcFlyInTheSky MartyMcFlyInTheSky added the enhancement New feature or request label Aug 23, 2024
@MartyMcFlyInTheSky MartyMcFlyInTheSky changed the title [FEATURE] Export magic variables to env in subshell execution [FEATURE] Export magic variables to env for script execution Aug 23, 2024
@ovalkonia
Copy link
Contributor

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

@MartyMcFlyInTheSky
Copy link
Author

MartyMcFlyInTheSky commented Aug 29, 2024

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
Copy link
Contributor

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
Copy link
Author

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.

@ovalkonia ovalkonia mentioned this issue Aug 29, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants