Skip to content
Merged
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
103 changes: 56 additions & 47 deletions daemon/terminal_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,57 @@ import (
"strings"
)

// Known terminal emulator process names
var knownTerminals = map[string]bool{
// Known terminal emulator process names (lowercase for case-insensitive matching)
var knownTerminals = []string{
// macOS
"Terminal": true,
"iTerm2": true,
"Alacritty": true,
"alacritty": true,
"kitty": true,
"WezTerm": true,
"wezterm": true,
"wezterm-gui": true,
"Hyper": true,
"Tabby": true,
"Warp": true,
"Ghostty": true,
"ghostty": true,
"terminal",
"iterm2",
"alacritty",
"kitty",
"wezterm",
"hyper",
"tabby",
"warp",
"ghostty",
// Linux
"gnome-terminal": true,
"gnome-terminal-": true, // gnome-terminal-server
"konsole": true,
"xfce4-terminal": true,
"xterm": true,
"urxvt": true,
"rxvt": true,
"terminator": true,
"tilix": true,
"st": true,
"foot": true,
"footclient": true,
"gnome-terminal",
"konsole",
"xfce4-terminal",
"xterm",
"urxvt",
"rxvt",
"terminator",
"tilix",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The st terminal emulator, which was present in the previous version, appears to have been removed from the knownTerminals list. This seems like an unintentional omission that would prevent st from being detected. I recommend adding it back.

Suggested change
"tilix",
"tilix",
"st",

"foot",
// IDE terminals
"code": true,
"Code": true,
"cursor": true,
"Cursor": true,
"code",
"cursor",
}

// Known terminal multiplexer process names
var knownMultiplexers = map[string]bool{
"tmux": true,
"screen": true,
"zellij": true,
// Known terminal multiplexer process names (lowercase for case-insensitive matching)
var knownMultiplexers = []string{
"tmux",
"screen",
"zellij",
}

// Known remote/container process names
var knownRemote = map[string]bool{
"sshd": true,
"docker": true,
"containerd": true,
// Known remote/container process names (lowercase for case-insensitive matching)
var knownRemote = []string{
"sshd",
"docker",
"containerd",
}

// matchKnownName checks if processName contains any of the known names (case-insensitive)
// Returns the matched known name if found, empty string otherwise
func matchKnownName(processName string, knownNames []string) string {
lowerName := strings.ToLower(processName)
for _, known := range knownNames {
if strings.Contains(lowerName, known) {
return known
}
}
return ""
}

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

// Check for multiplexers first (they're closer to the shell)
if multiplexer == "" && knownMultiplexers[processName] {
multiplexer = processName
if multiplexer == "" {
if matched := matchKnownName(processName, knownMultiplexers); matched != "" {
multiplexer = matched
}
}
Comment on lines +87 to 91
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This conditional assignment can be made more concise. Since matchKnownName returns an empty string when there's no match, you can directly assign its return value inside the if block. This avoids the nested if and the temporary matched variable.

		if multiplexer == "" {
			multiplexer = matchKnownName(processName, knownMultiplexers)
		}


// Check for terminals
if terminal == "" && knownTerminals[processName] {
terminal = processName
if terminal == "" {
if matched := matchKnownName(processName, knownTerminals); matched != "" {
terminal = matched
}
}
Comment on lines +94 to 98
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the multiplexer check above, this block can be simplified by directly assigning the result of matchKnownName.

		if terminal == "" {
			terminal = matchKnownName(processName, knownTerminals)
		}


// Check for remote connections
if terminal == "" && knownRemote[processName] {
terminal = processName
if terminal == "" {
if matched := matchKnownName(processName, knownRemote); matched != "" {
terminal = matched
}
}
Comment on lines +101 to 105
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block can also be simplified using the same pattern as the multiplexer and terminal checks.

		if terminal == "" {
			terminal = matchKnownName(processName, knownRemote)
		}


// If we found a terminal, we can stop
Expand Down
Loading