eww icon indicating copy to clipboard operation
eww copied to clipboard

[FEATURE] Initialize basic variables with shell output

Open ulinja opened this issue 2 years ago • 3 comments

Description of the requested feature

It is currently not possible to initialize basic variables using the output of a shell command. Basic variables can only be initialized using a literal value assignment:

(defvar current-volume 100)

My current workaround is to first spawn a window containing a widget which references the variable, and then updating the variable externally:

eww open my-bar && eww update current-volume=$(pamixer --get-volume)

It would be a nice addition to be able to initialize basic variables from shell output directly in eww.yuck.

Proposed configuration syntax

This could be accomplished by adding a simple boolean parameter, called for example execute, to the defvar-directive:

(defvar current-volume :execute true `pamixer --get-volume`)

If the parameter is true, the specified string gets executed in a spawned shell, and the shell's output gets assigned to the variable.

Additional context

No response

Edit: fix example code snippet.

ulinja avatar Aug 18 '23 10:08 ulinja

One workaround for now is to just use a polling variable with a very very high interval, that should effectively make the command only run once

elkowar avatar Aug 18 '23 11:08 elkowar

True, I didn't even think of that, because I wasn't sure if polling variables could be updated using eww update. As it turns out, they can, which is nice. Just tested it.

ulinja avatar Aug 18 '23 12:08 ulinja

Could still be nice to add something like this to remove an unnecessary counter and to make the solution a bit more straight forward.

(defpoll myVariable :interval "once" ...
)

Alternatively to “once”, setting the interval to zero could also be an input to disable the timer.

luposmi avatar Sep 24 '23 09:09 luposmi