Open emanuele6 opened 1 year ago
I like this idea.
For the %@ (multiple windows) case, would you want all the exec statements to run in sequence (one after another, each time waiting for the previous one to finish), or run in parallel (launch all at the same time, wait for all to finish)?
Hmm, I was thinking it would pass multiple arguments to the command, but running multiple commands could probably be useful too.
Passing multiple arguments is more versatile because you can use sh -c
to make it run multiple commands:
# sequential
xdotool search --sync --class foo exec --terminator end sh -c 'for w do cmd arg "$w"; done' _ %@ end
# parallel
xdotool search --sync --class foo exec --terminator end sh -c 'for w do cmd arg "$w" & done; wait' _ %@ end
So I think making %@
expand to multiple arguments and run a single command would be a better default, but maybe there could be a --multiple
option that changes how %@
is expanded.
Not sure which should be the default between parallel execution and sequential execution when running multiple commands, I think I prefer running them in parallel.
Sounds like we're on the same pag, I think! :)
For now, based on what you've described, having window references %1, %@, etc simply expand in the command could be useful. A flag would be useful to change the behavior of %@ from multiple arguments to multiple processes, where the default would be multiple arguments.
Multiple processes flag could be a convenient shortcut for folks who don't want to use or don't know about stuff like &
/wait
or xargs
.
Thinking further, with multiple processes, we could also prefix the output of each command with the window id to make other processing easier -- something like xdotool search ... exec --multiple xprop -id %@
could run xprop -id X
for each window and prefix the output with the window's ID. That's a bit more complex in the code, so I'm willing to wait until someone asks for this and wouldn't necessarily need this (multiple + output prefixing) feature for what we're discussing.
Thoughts?
Sounds good, thank you! =)
I put together a quick change which does the argument expansion but does not have the multiple-process flag:
After building, I tested with the following to pass %@ to a shell which invokes xprop -id WINDOW ...
for each window:
/xdotool search xterm exec --sync sh -c 'for w do echo -n $w: ; xprop -id $w WM_LOCALE_NAME; done' - %@
Defaulting to search window name, class, classname, and role
12582942:WM_LOCALE_NAME(STRING) = "en_GB.UTF-8"
14680094:WM_LOCALE_NAME(STRING) = "en_GB.UTF-8"
The pull request is #433
It would be nice if
exec
was able to use the window id of windows in the window stack =)Something like