1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! tmux session profile auto-application for the gateway tab.
//!
//! Extracted from `gateway` to keep session lifecycle I/O separate from
//! profile matching logic.
//!
//! Contains:
//! - `apply_tmux_session_profile` — match session name against configured profiles
//! - `apply_profile_to_gateway_tab` — apply a matched profile's visual settings
use crate::app::window_state::WindowState;
impl WindowState {
/// Apply a profile based on tmux session name
///
/// This checks for profiles that match the session name pattern and applies
/// them to the gateway tab. Profile matching uses glob patterns (e.g., "work-*",
/// "*-production").
pub(crate) fn apply_tmux_session_profile(&mut self, session_name: &str) {
// First, check if there's a fixed tmux_profile configured
if let Some(ref profile_name) = self.config.load().tmux.tmux_profile {
if let Some(profile) = self.overlay_ui.profile_manager.find_by_name(profile_name) {
let profile_id = profile.id;
let profile_display = profile.name.clone();
crate::debug_info!(
"TMUX",
"Applying configured tmux_profile '{}' for session '{}'",
profile_display,
session_name
);
self.apply_profile_to_gateway_tab(profile_id, &profile_display);
return;
} else {
crate::debug_info!(
"TMUX",
"Configured tmux_profile '{}' not found",
profile_name
);
}
}
// Then, check for pattern-based matching
if let Some(profile) = self
.overlay_ui
.profile_manager
.find_by_tmux_session(session_name)
{
let profile_id = profile.id;
let profile_display = profile.name.clone();
crate::debug_info!(
"TMUX",
"Auto-switching to profile '{}' for tmux session '{}'",
profile_display,
session_name
);
self.apply_profile_to_gateway_tab(profile_id, &profile_display);
} else {
crate::debug_info!(
"TMUX",
"No profile matches tmux session '{}' - consider adding tmux_session_patterns to a profile",
session_name
);
}
}
/// Apply a profile to the tmux gateway tab
pub(crate) fn apply_profile_to_gateway_tab(
&mut self,
profile_id: crate::profile::ProfileId,
profile_name: &str,
) {
// Extract profile settings before borrowing tab_manager
let profile_settings = self.overlay_ui.profile_manager.get(&profile_id).map(|p| {
(
p.tab_name.clone(),
p.icon.clone(),
p.badge_text.clone(),
p.command.clone(),
p.command_args.clone(),
p.source.is_dynamic(),
)
});
if let Some(gateway_tab_id) = self.tmux_state.tmux_gateway_tab_id
&& let Some(tab) = self.tab_manager.get_tab_mut(gateway_tab_id)
{
let mut pending_command: Option<(String, Option<Vec<String>>, bool)> = None;
if let Some((tab_name, icon, badge_text, command, command_args, remote_origin)) =
profile_settings
{
// Same state change as a host/directory switch: the tab's
// title, icon, and per-tab badge are saved for the revert
// and the tooltip names the rule (UX.md PR5).
let current_title = tab.title.clone();
let change = tab.profile.apply_auto(
crate::tab::AutoRule::Host,
crate::tab::AutoApply {
profile_id,
title: tab_name.unwrap_or_else(|| profile_name.to_string()),
icon,
badge_text,
reason: "tmux session".to_string(),
},
¤t_title,
);
if let crate::tab::TitleChange::Set(title) = change {
tab.set_title(&title);
}
// Deferred rather than run here: the tmux session name that selected
// this profile is pattern-matched, so the command needs the same
// confirmation the hostname path uses. Dispatched once `tab` is free.
pending_command = command.map(|cmd| (cmd, command_args, remote_origin));
}
if let Some((command, command_args, remote_origin)) = pending_command {
self.dispatch_profile_command(
profile_id,
profile_name,
Some(&command),
command_args.as_deref(),
remote_origin,
"a tmux session pattern",
);
}
// Show notification about profile switch
self.show_toast(format!("tmux: Profile '{}' applied", profile_name));
log::info!(
"Applied profile '{}' for tmux session (gateway tab {})",
profile_name,
gateway_tab_id
);
}
// Apply profile badge settings (color, font, margins, etc.)
if let Some(profile) = self.overlay_ui.profile_manager.get(&profile_id) {
let profile_clone = profile.clone();
self.apply_profile_badge(&profile_clone);
}
}
}