diff --git a/src/main.rs b/src/main.rs index e1026d2..5332cbc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -443,6 +443,12 @@ fn run_tui(manager: Manager, config_meta: config::ConfigMeta) -> Result<()> { // Startup checks startup_checks()?; + if crate::tmux::pane::is_inside_tmux() { + if let Err(err) = crate::tmux::pane::ensure_worktrees_explorer_tab() { + eprintln!("warning: failed to name worktree explorer tab: {err}"); + } + } + // Set up terminal crossterm::terminal::enable_raw_mode()?; let mut stdout = std::io::stdout(); @@ -1052,6 +1058,12 @@ fn run_forest_tui() -> Result<()> { // Startup checks startup_checks()?; + if crate::tmux::pane::is_inside_tmux() { + if let Err(err) = crate::tmux::pane::ensure_worktrees_explorer_tab() { + eprintln!("warning: failed to name worktree explorer tab: {err}"); + } + } + // Set up terminal crossterm::terminal::enable_raw_mode()?; let mut stdout = std::io::stdout(); diff --git a/src/tmux/pane.rs b/src/tmux/pane.rs index a2e5319..3f84821 100644 --- a/src/tmux/pane.rs +++ b/src/tmux/pane.rs @@ -4,6 +4,9 @@ use std::path::Path; use std::process::Command; use std::time::{SystemTime, UNIX_EPOCH}; +/// Stable name for the cwt navigator tab/window that stays open as a worktree explorer. +pub const WORKTREES_EXPLORER_NAME: &str = "cwt:worktrees"; + /// Information about a tmux pane. #[derive(Debug, Clone)] pub struct PaneInfo { @@ -47,6 +50,20 @@ pub fn create_pane(worktree_path: &Path, command: &str, pane_title: &str) -> Res } } +/// Ensure the current tab/window is named as the persistent worktree explorer. +pub fn ensure_worktrees_explorer_tab() -> Result<()> { + match preferred_multiplexer() { + Multiplexer::Zellij => { + zellij_action(&["rename-tab", WORKTREES_EXPLORER_NAME])?; + Ok(()) + } + Multiplexer::Tmux => { + tmux(&["rename-window", WORKTREES_EXPLORER_NAME])?; + Ok(()) + } + } +} + /// Focus (select) an existing tmux pane by switching to its window first. pub fn focus_pane(pane_id: &str) -> Result<()> { match preferred_multiplexer() {