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

Support multiple command executions with on_usb_<event>_execute #133

Open
bil0u opened this issue Nov 20, 2023 · 1 comment
Open

Support multiple command executions with on_usb_<event>_execute #133

bil0u opened this issue Nov 20, 2023 · 1 comment

Comments

@bil0u
Copy link

bil0u commented Nov 20, 2023

Hi there, thanks for your work on this project.

I'm using a custom version of m1ddc to send switching input commands to my displays when my USB switch is disconnected, and the binary needs to be called for each display.

It would be great to support execution of multiple commands when usb events are fired.

An easy implementation (tested) would be to split the command string on the ; delimiter, and call each command successively.


try_run_command(execute_command)
.unwrap_or_else(|err| error!("Error executing external command '{}': {}", execute_command, err))

would be replaced by

for subcommand in execute_command.split(";") {
    let subcommand = subcommand.trim();
    if !subcommand.is_empty() {
        try_run_command(subcommand).unwrap_or_else(|err| error!("Error executing external command '{}': {}", subcommand, err));
    }
}

What do you think ?

@bil0u bil0u changed the title Support multiple command executions using on_usb_<event>_execute Support multiple command executions with on_usb_<event>_execute Nov 20, 2023
@zerosym
Copy link

zerosym commented Jan 20, 2024

I am also using m1ddc to swap multiple monitors at the same time. You can chain commands in this fashion without needing anything additional if you wish:

# Example
on_usb_connect_execute = "sh -c \"m1ddc display 1 set input 1 && m1ddc display 2 set input 1\""

Unsure if escaping the inner quotations is needed here, but this seems to work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants