diff --git a/.centy/issues/5702708c-716d-4edc-ad72-c83bde1e514d.md b/.centy/issues/5702708c-716d-4edc-ad72-c83bde1e514d.md index 401aa0e..1e426b5 100644 --- a/.centy/issues/5702708c-716d-4edc-ad72-c83bde1e514d.md +++ b/.centy/issues/5702708c-716d-4edc-ad72-c83bde1e514d.md @@ -1,10 +1,10 @@ --- # This file is managed by Centy. Use the Centy CLI to modify it. displayNumber: 52 -status: in-progress +status: closed priority: 2 createdAt: 2026-03-21T19:08:45.344228+00:00 -updatedAt: 2026-03-21T19:09:55.102321+00:00 +updatedAt: 2026-03-21T19:18:15.833046+00:00 --- # tmux as editor: session creation only works when a post:open hook is configured diff --git a/src/commands/open/mod.rs b/src/commands/open/mod.rs index d368104..021462e 100644 --- a/src/commands/open/mod.rs +++ b/src/commands/open/mod.rs @@ -83,7 +83,7 @@ pub fn cmd_open(issue_ref: Option<&str>, force_editor: bool, no_hooks: bool) -> } } (Some(cmd), None) => { - opener::open_in_editor(&workspace.path, cmd, config.editor.background)?; + opener::open_editor_or_terminal(&workspace.path, cmd, config.editor.background)?; } (None, Some(script)) => { eprintln!("Running post:open hook…"); diff --git a/src/opener/mod.rs b/src/opener/mod.rs index a686981..08c1eb1 100644 --- a/src/opener/mod.rs +++ b/src/opener/mod.rs @@ -28,7 +28,10 @@ fn open_hook_in_auto_terminal(path: &Path, init_script: &str) -> Result { if which::which("wt").is_ok() && terminal::try_terminal_with_init(path, "wt", init_script)? { return Ok(true); } - + if which::which("tmux").is_ok() && terminal::try_terminal_with_init(path, "tmux", init_script)? + { + return Ok(true); + } #[cfg(target_os = "macos")] { let candidates: &[(&str, &str)] = &[ @@ -45,7 +48,6 @@ fn open_hook_in_auto_terminal(path: &Path, init_script: &str) -> Result { // LLVM_COV_EXCL_STOP } } - Ok(false) } @@ -56,9 +58,7 @@ fn open_hook_in_auto_terminal(path: &Path, init_script: &str) -> Result { /// Returns an error if the editor or terminal command fails to spawn. pub fn open_with_hook(path: &Path, cmd: &str, init: &str, background: bool) -> Result { if terminal::try_terminal_with_init(path, cmd, init)? { - // LLVM_COV_EXCL_START return Ok(true); - // LLVM_COV_EXCL_STOP } open_in_editor(path, cmd, background)?; open_hook_in_auto_terminal(path, init) @@ -74,7 +74,6 @@ pub fn open_in_editor(path: &Path, command: &str, background: bool) -> Result<() let path_str = path .to_str() .context("Workspace path contains non-UTF-8 characters")?; - let cmd_str = if command.contains(" . ") || command.ends_with(" .") || command == "." { command.replacen(" .", &format!(" {path_str}"), 1) } else { @@ -85,6 +84,17 @@ pub fn open_in_editor(path: &Path, command: &str, background: bool) -> Result<() .with_context(|| format!("Failed to open editor with command: {cmd_str}")) } +/// Open `path` with `cmd`; uses terminal-specific logic if `cmd` is a known terminal, +/// otherwise opens as an editor. +/// # Errors +/// Returns an error if the spawn or editor command fails. +pub fn open_editor_or_terminal(path: &Path, cmd: &str, background: bool) -> Result<()> { + if !terminal::try_terminal_with_init(path, cmd, "")? { + open_in_editor(path, cmd, background)?; + } + Ok(()) +} + #[cfg(test)] #[path = "opener_tests.rs"] mod tests; diff --git a/src/opener/opener_tests.rs b/src/opener/opener_tests.rs index 5082dfe..c2b6d95 100644 --- a/src/opener/opener_tests.rs +++ b/src/opener/opener_tests.rs @@ -25,3 +25,8 @@ fn test_open_in_editor_background() { let p = std::path::Path::new("/tmp/myproject"); open_in_editor(p, "echo", true).unwrap(); } +#[test] +fn test_open_editor_or_terminal_ide() { + let p = std::path::Path::new("/tmp/myproject"); + open_editor_or_terminal(p, "echo .", false).unwrap(); +}