diff --git a/crates/rhai_impl/src/updates/listen.rs b/crates/rhai_impl/src/updates/listen.rs index 57a125b..a4c410f 100644 --- a/crates/rhai_impl/src/updates/listen.rs +++ b/crates/rhai_impl/src/updates/listen.rs @@ -30,6 +30,7 @@ use tokio::sync::watch; pub fn handle_listen( var_name: String, props: &Map, + shell: String, store: ReactiveVarStore, tx: tokio::sync::mpsc::UnboundedSender, ) { @@ -76,7 +77,7 @@ pub fn handle_listen( tokio::spawn(async move { let mut child = unsafe { - Command::new("/bin/sh") + Command::new(&shell) .arg("-c") .arg(&cmd) // .kill_on_drop(true) diff --git a/crates/rhai_impl/src/updates/mod.rs b/crates/rhai_impl/src/updates/mod.rs index b376b7f..cb4d889 100644 --- a/crates/rhai_impl/src/updates/mod.rs +++ b/crates/rhai_impl/src/updates/mod.rs @@ -25,6 +25,7 @@ use std::sync::Mutex; use std::{collections::HashMap, sync::Arc, sync::RwLock}; use tokio::sync::mpsc::UnboundedSender; use tokio::sync::watch; +use std::process::Command; pub type ReactiveVarStore = Arc>>; pub static SHUTDOWN_REGISTRY: Lazy>>> = @@ -35,14 +36,23 @@ pub fn handle_state_changes( tx: UnboundedSender, store: ReactiveVarStore, ) { + // Check Dash and prefer if dash is installed. + let dash_installed: bool = Command::new("which") + .arg("dash") + .output() + .map(|o| o.status.success()) + .unwrap_or(false); + + let shell = if dash_installed { String::from("/bin/dash") } else { String::from("/bin/sh") }; + if let WidgetNode::Enter(children) = root_node { for child in children { match child { WidgetNode::Poll { var, props } => { - handle_poll(var.to_string(), props, store.clone(), tx.clone()); + handle_poll(var.to_string(), props, shell.clone(), store.clone(), tx.clone()); } WidgetNode::Listen { var, props } => { - handle_listen(var.to_string(), props, store.clone(), tx.clone()); + handle_listen(var.to_string(), props, shell.clone(), store.clone(), tx.clone()); } _ => {} } diff --git a/crates/rhai_impl/src/updates/poll.rs b/crates/rhai_impl/src/updates/poll.rs index edc7947..bf96c69 100644 --- a/crates/rhai_impl/src/updates/poll.rs +++ b/crates/rhai_impl/src/updates/poll.rs @@ -26,6 +26,7 @@ use tokio::time::sleep; pub fn handle_poll( var_name: String, props: &Map, + shell: String, store: ReactiveVarStore, tx: tokio::sync::mpsc::UnboundedSender, ) { @@ -57,7 +58,7 @@ pub fn handle_poll( tokio::spawn(async move { // Spawn a persistent shell - let mut child = match Command::new("/bin/sh") + let mut child = match Command::new(&shell) .stdin(std::process::Stdio::piped()) .stdout(std::process::Stdio::piped()) .spawn()