Skip to content
Open
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
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions src/tmux/pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down