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

Bind/run multiple actions at once #914

Open
YaLTeR opened this issue Jan 1, 2025 · 4 comments
Open

Bind/run multiple actions at once #914

YaLTeR opened this issue Jan 1, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@YaLTeR
Copy link
Owner

YaLTeR commented Jan 1, 2025

Allow binds to run several actions sequentially, e.g.:

Mod+G {
    focus-column-right
    consume-or-expel-window-left
}

And, more importantly, add some way to run several actions as a batch through IPC and niri msg action. This will allow doing several actions as one atomic sequence and with no delay in-between, which is currently impossible.

Here the binds and the IPC part should be straightforward, but I'm not sure how to parse the arguments in niri msg action. Maybe clap offers something?

Another question is what to do if only one action in the sequence fails a check like allow-when-locked. Here I guess we ignore just the action that fails the check, same as what would happen if you were to run several niri msg action commands one after another.

@YaLTeR YaLTeR added the enhancement New feature or request label Jan 1, 2025
@YaLTeR
Copy link
Owner Author

YaLTeR commented Jan 2, 2025

Idea from @calops for CLI:

you could also just have an option to read actions from stdin, where you can just put all of them separated with newlines

Though, I'm not sure if you can run a clap parser on stdin to parse the arguments.

@calops
Copy link
Contributor

calops commented Jan 2, 2025

You should be able to run a clap parser on any string manually. It would have to be a subset of the global parser but it sounds doable.

@bbb651
Copy link
Contributor

bbb651 commented Jan 12, 2025

Clap doesn't support it currently, someone mentioned this as a workaround:

I resorted to collecting std::env::args() into a Vec<String>, iterated over .split("--"), provided the zeroth argument (program name) at index 0 for each split and fed those to MagicalArgs::from_iter. It is bad in the sense that it abolutely requires the presence of -- between subcommands.

In hindsight, it is a rather obvious workaround that would have saved me half a day of frustration. Retains all the nice stuff of structopt and scales until the limits of linux command lines are reached. If only clap/structopt could parse partially and yield the remainder instead of failing with a hardcoded unkown argument error...

This breaks -- and presumably breaks clap_complete (which we don't have yet anyway), but otherwise seems like pretty good workaround.

@calops
Copy link
Contributor

calops commented Jan 12, 2025

This issue only seems to relate to chaining commands in the program arguments. You can still use the exact same workaround you're talking about with the contents of stdin instead of splitting on --. You would still need to tokenize each line but that's fairly simple. We probably don't need anything but handling quotes and then splitting on spaces (or maybe IFS).

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

3 participants