Skip to content

Commit 18cea44

Browse files
committed
v0.3.3 — detect Ghostty inside tmux via GHOSTTY_RESOURCES_DIR fallback
1 parent b352769 commit 18cea44

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opencode-alert",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"description": "OS notifications for OpenCode — alerts when your agent needs attention",
55
"type": "module",
66
"main": "src/index.ts",

‎src/notify.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export function detectProtocol(): NotifyProtocol {
4949
} else if (env["TERM_PROGRAM"] === "iTerm.app" || env["ITERM_SESSION_ID"]) {
5050
cachedProtocol = "osc9";
5151
} else {
52+
// Catch-all: osc777 covers Ghostty, WezTerm, foot, rxvt-unicode.
53+
// This is correct even when TERM_PROGRAM=tmux (Ghostty inside tmux) —
54+
// Ghostty uses osc777, so the fallback protocol matches by coincidence.
5255
cachedProtocol = "osc777";
5356
}
5457

‎src/terminal.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ export function detectTerminal(override?: string | null): TerminalInfo | null {
6060
if (termProgram.includes("hyper")) return TERMINALS["hyper"]!;
6161
}
6262

63+
// Ghostty sets GHOSTTY_RESOURCES_DIR even inside tmux (where TERM_PROGRAM
64+
// gets overwritten to "tmux" after a server restart)
65+
if (env["GHOSTTY_RESOURCES_DIR"]) return TERMINALS["ghostty"]!;
66+
6367
// LC_TERMINAL (set by some terminals)
6468
const lcTerminal = env["LC_TERMINAL"]?.toLowerCase();
6569
if (lcTerminal) {

‎test/terminal.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { detectTerminal } from "../src/terminal.js";
88

99
const ENV_KEYS = [
1010
"TERM_PROGRAM",
11+
"GHOSTTY_RESOURCES_DIR",
1112
"LC_TERMINAL",
1213
"KITTY_WINDOW_ID",
1314
"TERM",
@@ -124,6 +125,35 @@ describe("detectTerminal", () => {
124125
});
125126
});
126127

128+
// -- GHOSTTY_RESOURCES_DIR fallback (tmux case) -------------------------
129+
130+
describe("GHOSTTY_RESOURCES_DIR fallback", () => {
131+
test("detects Ghostty when TERM_PROGRAM=tmux but GHOSTTY_RESOURCES_DIR is set", () => {
132+
process.env["TERM_PROGRAM"] = "tmux";
133+
process.env["GHOSTTY_RESOURCES_DIR"] = "/usr/share/ghostty";
134+
const result = detectTerminal();
135+
expect(result).not.toBeNull();
136+
expect(result!.name).toBe("Ghostty");
137+
expect(result!.protocol).toBe("osc777");
138+
});
139+
140+
test("detects Ghostty via GHOSTTY_RESOURCES_DIR when no TERM_PROGRAM is set", () => {
141+
process.env["GHOSTTY_RESOURCES_DIR"] = "/usr/share/ghostty";
142+
const result = detectTerminal();
143+
expect(result).not.toBeNull();
144+
expect(result!.name).toBe("Ghostty");
145+
});
146+
147+
test("TERM_PROGRAM=ghostty takes precedence over GHOSTTY_RESOURCES_DIR", () => {
148+
process.env["TERM_PROGRAM"] = "ghostty";
149+
process.env["GHOSTTY_RESOURCES_DIR"] = "/usr/share/ghostty";
150+
const result = detectTerminal();
151+
expect(result).not.toBeNull();
152+
expect(result!.name).toBe("Ghostty");
153+
// Both paths return Ghostty — but TERM_PROGRAM is checked first
154+
});
155+
});
156+
127157
// -- LC_TERMINAL detection ---------------------------------------------
128158

129159
describe("LC_TERMINAL detection", () => {
@@ -187,6 +217,13 @@ describe("detectTerminal", () => {
187217
expect(result!.name).toBe("Ghostty");
188218
});
189219

220+
test("TERM_PROGRAM (non-ghostty) takes precedence over GHOSTTY_RESOURCES_DIR", () => {
221+
process.env["TERM_PROGRAM"] = "WezTerm";
222+
process.env["GHOSTTY_RESOURCES_DIR"] = "/usr/share/ghostty";
223+
const result = detectTerminal();
224+
expect(result!.name).toBe("WezTerm");
225+
});
226+
190227
test("KITTY_WINDOW_ID takes precedence over TERM", () => {
191228
process.env["KITTY_WINDOW_ID"] = "12345";
192229
process.env["TERM"] = "alacritty";

0 commit comments

Comments
 (0)