Skip to content

Commit f26f640

Browse files
authored
Merge pull request #615 from multiplex55/codex/add-wezterm-support-to-shell-plugin
Add WezTerm support for shell plugin
2 parents bfe904c + a9551d2 commit f26f640

2 files changed

Lines changed: 60 additions & 5 deletions

File tree

src/actions/shell.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
pub fn run(cmd: &str, keep_open: bool) -> anyhow::Result<()> {
2-
let mut command = {
1+
use crate::plugins::shell::use_wezterm;
2+
3+
pub fn build_shell_command(cmd: &str, keep_open: bool) -> (std::process::Command, String) {
4+
let arg = if keep_open { "/K" } else { "/C" };
5+
if use_wezterm() {
6+
let mut c = std::process::Command::new("wezterm");
7+
c.arg("start").arg("--").arg("cmd").arg(arg).arg(cmd);
8+
let desc = format!("wezterm start -- cmd {arg} {cmd}");
9+
(c, desc)
10+
} else {
311
let mut c = std::process::Command::new("cmd");
4-
c.arg(if keep_open { "/K" } else { "/C" }).arg(cmd);
5-
c
6-
};
12+
c.arg(arg).arg(cmd);
13+
let desc = format!("cmd {arg} {cmd}");
14+
(c, desc)
15+
}
16+
}
17+
18+
pub fn run(cmd: &str, keep_open: bool) -> anyhow::Result<()> {
19+
let (mut command, _) = build_shell_command(cmd, keep_open);
720
command.spawn().map(|_| ()).map_err(|e| e.into())
821
}
922

src/plugins/shell.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use crate::actions::Action;
22
use crate::plugin::Plugin;
3+
use eframe::egui;
34
use fuzzy_matcher::skim::SkimMatcherV2;
45
use fuzzy_matcher::FuzzyMatcher;
56
use serde::{Deserialize, Serialize};
7+
use std::sync::atomic::{AtomicBool, Ordering};
68

79
pub const SHELL_CMDS_FILE: &str = "shell_cmds.json";
810

@@ -17,6 +19,25 @@ pub struct ShellCmdEntry {
1719
pub keep_open: bool,
1820
}
1921

22+
#[derive(Serialize, Deserialize, Clone)]
23+
pub struct ShellPluginSettings {
24+
pub open_in_wezterm: bool,
25+
}
26+
27+
impl Default for ShellPluginSettings {
28+
fn default() -> Self {
29+
Self {
30+
open_in_wezterm: false,
31+
}
32+
}
33+
}
34+
35+
static USE_WEZTERM: AtomicBool = AtomicBool::new(false);
36+
37+
pub fn use_wezterm() -> bool {
38+
USE_WEZTERM.load(Ordering::Relaxed)
39+
}
40+
2041
fn default_autocomplete() -> bool {
2142
true
2243
}
@@ -220,4 +241,25 @@ impl Plugin for ShellPlugin {
220241
},
221242
]
222243
}
244+
245+
fn default_settings(&self) -> Option<serde_json::Value> {
246+
serde_json::to_value(ShellPluginSettings::default()).ok()
247+
}
248+
249+
fn apply_settings(&mut self, value: &serde_json::Value) {
250+
if let Ok(cfg) = serde_json::from_value::<ShellPluginSettings>(value.clone()) {
251+
USE_WEZTERM.store(cfg.open_in_wezterm, Ordering::Relaxed);
252+
}
253+
}
254+
255+
fn settings_ui(&mut self, ui: &mut egui::Ui, value: &mut serde_json::Value) {
256+
let mut cfg: ShellPluginSettings =
257+
serde_json::from_value(value.clone()).unwrap_or_default();
258+
ui.checkbox(&mut cfg.open_in_wezterm, "Open commands in WezTerm");
259+
USE_WEZTERM.store(cfg.open_in_wezterm, Ordering::Relaxed);
260+
match serde_json::to_value(&cfg) {
261+
Ok(v) => *value = v,
262+
Err(e) => tracing::error!("failed to serialize shell settings: {e}"),
263+
}
264+
}
223265
}

0 commit comments

Comments
 (0)