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

Fork command to background #64

Open
RampedIndent opened this issue Feb 20, 2023 · 2 comments
Open

Fork command to background #64

RampedIndent opened this issue Feb 20, 2023 · 2 comments

Comments

@RampedIndent
Copy link

So i am trying to rewrite my polybar launch script in rust, in basg you can for a command to the background with the & symbol like so

MONITOR=$m polybar --reload mainbar-bspwm -c ~/.config/polybar/config.ini &

Is there a way to do this with xshell?

@matklad
Copy link
Owner

matklad commented Feb 20, 2023

No direct way: you’ll need something like

std::process::Comand::from(cmd!(…)).spawn()

for that effect.

we probably should addd spawn though, to add structured concurrency

@RampedIndent
Copy link
Author

Ended up using rayon to do it

#[derive(Debug, Clone, Serialize, Deserialize)] // we'll be cloning it later on
pub struct DispConfig {
    display: String,
    bar_name: String,
}

#[derive(Clone, Debug)] // we'll be cloning it later on
#[derive(Serialize, Deserialize)] // we'll be cloning it later on
struct ComputerConfig {
    displays: Vec<DispConfig>,
}


let monitors = IntoParallelIterator::into_par_iter(computer.displays.clone());
rayon::spawn(move || {
    monitors
        .filter(|monitor| !monitor.bar_name.is_empty())
        .try_for_each(|monitor| {
            let sh = Shell::new()?;
            let display = monitor.display;
            info!("{display:?}");
            let barname = monitor.bar_name;
            let config = "~/.config/polybar/config.ini";
            cmd!(sh, "polybar --reload {barname} -c {config}")
                .env("MONITOR", display)
                // .env("FC_DEBUG", "1")
                .run()?;
            anyhow::Ok(())
        });
});

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