diff --git a/src/actions/shell.rs b/src/actions/shell.rs index 9fbe156a..d6d7cc32 100644 --- a/src/actions/shell.rs +++ b/src/actions/shell.rs @@ -1,9 +1,22 @@ -pub fn run(cmd: &str, keep_open: bool) -> anyhow::Result<()> { - let mut command = { +use crate::plugins::shell::use_wezterm; + +pub fn build_shell_command(cmd: &str, keep_open: bool) -> (std::process::Command, String) { + let arg = if keep_open { "/K" } else { "/C" }; + if use_wezterm() { + let mut c = std::process::Command::new("wezterm"); + c.arg("start").arg("--").arg("cmd").arg(arg).arg(cmd); + let desc = format!("wezterm start -- cmd {arg} {cmd}"); + (c, desc) + } else { let mut c = std::process::Command::new("cmd"); - c.arg(if keep_open { "/K" } else { "/C" }).arg(cmd); - c - }; + c.arg(arg).arg(cmd); + let desc = format!("cmd {arg} {cmd}"); + (c, desc) + } +} + +pub fn run(cmd: &str, keep_open: bool) -> anyhow::Result<()> { + let (mut command, _) = build_shell_command(cmd, keep_open); command.spawn().map(|_| ()).map_err(|e| e.into()) } diff --git a/src/plugins/shell.rs b/src/plugins/shell.rs index 83b4bdc4..3616c834 100644 --- a/src/plugins/shell.rs +++ b/src/plugins/shell.rs @@ -1,8 +1,10 @@ use crate::actions::Action; use crate::plugin::Plugin; +use eframe::egui; use fuzzy_matcher::skim::SkimMatcherV2; use fuzzy_matcher::FuzzyMatcher; use serde::{Deserialize, Serialize}; +use std::sync::atomic::{AtomicBool, Ordering}; pub const SHELL_CMDS_FILE: &str = "shell_cmds.json"; @@ -17,6 +19,25 @@ pub struct ShellCmdEntry { pub keep_open: bool, } +#[derive(Serialize, Deserialize, Clone)] +pub struct ShellPluginSettings { + pub open_in_wezterm: bool, +} + +impl Default for ShellPluginSettings { + fn default() -> Self { + Self { + open_in_wezterm: false, + } + } +} + +static USE_WEZTERM: AtomicBool = AtomicBool::new(false); + +pub fn use_wezterm() -> bool { + USE_WEZTERM.load(Ordering::Relaxed) +} + fn default_autocomplete() -> bool { true } @@ -220,4 +241,25 @@ impl Plugin for ShellPlugin { }, ] } + + fn default_settings(&self) -> Option { + serde_json::to_value(ShellPluginSettings::default()).ok() + } + + fn apply_settings(&mut self, value: &serde_json::Value) { + if let Ok(cfg) = serde_json::from_value::(value.clone()) { + USE_WEZTERM.store(cfg.open_in_wezterm, Ordering::Relaxed); + } + } + + fn settings_ui(&mut self, ui: &mut egui::Ui, value: &mut serde_json::Value) { + let mut cfg: ShellPluginSettings = + serde_json::from_value(value.clone()).unwrap_or_default(); + ui.checkbox(&mut cfg.open_in_wezterm, "Open commands in WezTerm"); + USE_WEZTERM.store(cfg.open_in_wezterm, Ordering::Relaxed); + match serde_json::to_value(&cfg) { + Ok(v) => *value = v, + Err(e) => tracing::error!("failed to serialize shell settings: {e}"), + } + } }