Skip to content

Commit 16cf5d9

Browse files
committed
fix(daemon): improve terminal/multiplexer process name matching
Use case-insensitive substring matching instead of exact map lookups to handle process names like "tmux: server" that weren't being matched before. This makes the terminal resolver more robust across different systems and process naming conventions.
1 parent 8de003f commit 16cf5d9

1 file changed

Lines changed: 56 additions & 47 deletions

File tree

daemon/terminal_resolver.go

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,57 @@ import (
77
"strings"
88
)
99

10-
// Known terminal emulator process names
11-
var knownTerminals = map[string]bool{
10+
// Known terminal emulator process names (lowercase for case-insensitive matching)
11+
var knownTerminals = []string{
1212
// macOS
13-
"Terminal": true,
14-
"iTerm2": true,
15-
"Alacritty": true,
16-
"alacritty": true,
17-
"kitty": true,
18-
"WezTerm": true,
19-
"wezterm": true,
20-
"wezterm-gui": true,
21-
"Hyper": true,
22-
"Tabby": true,
23-
"Warp": true,
24-
"Ghostty": true,
25-
"ghostty": true,
13+
"terminal",
14+
"iterm2",
15+
"alacritty",
16+
"kitty",
17+
"wezterm",
18+
"hyper",
19+
"tabby",
20+
"warp",
21+
"ghostty",
2622
// Linux
27-
"gnome-terminal": true,
28-
"gnome-terminal-": true, // gnome-terminal-server
29-
"konsole": true,
30-
"xfce4-terminal": true,
31-
"xterm": true,
32-
"urxvt": true,
33-
"rxvt": true,
34-
"terminator": true,
35-
"tilix": true,
36-
"st": true,
37-
"foot": true,
38-
"footclient": true,
23+
"gnome-terminal",
24+
"konsole",
25+
"xfce4-terminal",
26+
"xterm",
27+
"urxvt",
28+
"rxvt",
29+
"terminator",
30+
"tilix",
31+
"foot",
3932
// IDE terminals
40-
"code": true,
41-
"Code": true,
42-
"cursor": true,
43-
"Cursor": true,
33+
"code",
34+
"cursor",
4435
}
4536

46-
// Known terminal multiplexer process names
47-
var knownMultiplexers = map[string]bool{
48-
"tmux": true,
49-
"screen": true,
50-
"zellij": true,
37+
// Known terminal multiplexer process names (lowercase for case-insensitive matching)
38+
var knownMultiplexers = []string{
39+
"tmux",
40+
"screen",
41+
"zellij",
5142
}
5243

53-
// Known remote/container process names
54-
var knownRemote = map[string]bool{
55-
"sshd": true,
56-
"docker": true,
57-
"containerd": true,
44+
// Known remote/container process names (lowercase for case-insensitive matching)
45+
var knownRemote = []string{
46+
"sshd",
47+
"docker",
48+
"containerd",
49+
}
50+
51+
// matchKnownName checks if processName contains any of the known names (case-insensitive)
52+
// Returns the matched known name if found, empty string otherwise
53+
func matchKnownName(processName string, knownNames []string) string {
54+
lowerName := strings.ToLower(processName)
55+
for _, known := range knownNames {
56+
if strings.Contains(lowerName, known) {
57+
return known
58+
}
59+
}
60+
return ""
5861
}
5962

6063
// ResolveTerminal walks up the process tree starting from ppid
@@ -81,18 +84,24 @@ func ResolveTerminal(ppid int) (terminal string, multiplexer string) {
8184
}
8285

8386
// Check for multiplexers first (they're closer to the shell)
84-
if multiplexer == "" && knownMultiplexers[processName] {
85-
multiplexer = processName
87+
if multiplexer == "" {
88+
if matched := matchKnownName(processName, knownMultiplexers); matched != "" {
89+
multiplexer = matched
90+
}
8691
}
8792

8893
// Check for terminals
89-
if terminal == "" && knownTerminals[processName] {
90-
terminal = processName
94+
if terminal == "" {
95+
if matched := matchKnownName(processName, knownTerminals); matched != "" {
96+
terminal = matched
97+
}
9198
}
9299

93100
// Check for remote connections
94-
if terminal == "" && knownRemote[processName] {
95-
terminal = processName
101+
if terminal == "" {
102+
if matched := matchKnownName(processName, knownRemote); matched != "" {
103+
terminal = matched
104+
}
96105
}
97106

98107
// If we found a terminal, we can stop

0 commit comments

Comments
 (0)