Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .centy/issues/5702708c-716d-4edc-ad72-c83bde1e514d.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/commands/open/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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…");
Expand Down
20 changes: 15 additions & 5 deletions src/opener/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ fn open_hook_in_auto_terminal(path: &Path, init_script: &str) -> Result<bool> {
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)] = &[
Expand All @@ -45,7 +48,6 @@ fn open_hook_in_auto_terminal(path: &Path, init_script: &str) -> Result<bool> {
// LLVM_COV_EXCL_STOP
}
}

Ok(false)
}

Expand All @@ -56,9 +58,7 @@ fn open_hook_in_auto_terminal(path: &Path, init_script: &str) -> Result<bool> {
/// 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<bool> {
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)
Expand All @@ -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 {
Expand All @@ -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;
5 changes: 5 additions & 0 deletions src/opener/opener_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Loading