@@ -8,6 +8,7 @@ import { detectTerminal } from "../src/terminal.js";
88
99const 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