matklad / xshell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fork command to background

RampedIndent opened this issue · comments

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?

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

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(())
        });
});