Files
coucou/NotchBuddy/Sources/App/TerminalTarget.swift
Mateus AmaralandClaude Opus 5.5 638a4ca8ae Open terminal: bring back the app the session runs in
"Open terminal" and the Jump to terminal shortcut picked the first running
app from a fixed list (Terminal, iTerm, kitty, Ghostty). Sessions in any
other terminal (cmux, Warp, WezTerm, Alacritty...) got a new Terminal.app
window instead.

The hook already sends the session's app as bundle_id. Keep it on the task
next to sessionCwd and activate that app first, then fall back to the known
terminals (now including cmux, Warp, WezTerm and Alacritty), then
Terminal.app as before. The three copies of the list now share
TerminalTarget, which has Foundation-only tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 09:14:28 -03:00

26 lines
1.2 KiB
Swift

import Foundation
/// Picks which app "Open terminal" / ⌃⌥T should bring to the front.
/// Foundation only, so it can be tested without AppKit (see scripts/test-terminal-target.sh).
enum TerminalTarget {
/// Terminals tried, in order, when the session's own app is unknown or not running.
static let knownTerminals = [
"com.apple.Terminal", "com.googlecode.iterm2", "net.kovidgoyal.kitty",
"com.mitchellh.ghostty", "com.cmuxterm.app", "dev.warp.Warp-Stable",
"com.github.wez.wezterm", "org.alacritty",
]
/// Bundle IDs to try, in order: the app the session runs in (from the hook's
/// `bundle_id`, i.e. `__CFBundleIdentifier`), then the known terminals.
static func candidates(sessionBundleId: String?) -> [String] {
let own = sessionBundleId?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
guard !own.isEmpty else { return knownTerminals }
return [own] + knownTerminals.filter { $0 != own }
}
/// First candidate that is currently running, or nil.
static func pick(sessionBundleId: String?, running: Set<String>) -> String? {
candidates(sessionBundleId: sessionBundleId).first { running.contains($0) }
}
}