Skip to content

Commit da1096c

Browse files
committed
TerminalShell: better support for Ghostty
1 parent 1e32a95 commit da1096c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/detection/terminalshell/terminalshell.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,25 @@ static bool getTerminalVersionZed(FFstrbuf* exe, FFstrbuf* version)
576576
return true;
577577
}
578578

579+
static bool getTerminalVersionGhostty(FFstrbuf* exe, FFstrbuf* version)
580+
{
581+
const char* env = getenv("TERM_PROGRAM_VERSION");
582+
if (env)
583+
{
584+
ffStrbufAppendS(version, env);
585+
// 1.1.3-arch1
586+
ffStrbufSubstrBeforeFirstC(version, '-');
587+
if(version->length > 0) return true;
588+
}
589+
590+
if(!getExeVersionRaw(exe, version)) return false;
591+
// Ghostty 1.1.3-arch1\n\nVersion\n...
592+
ffStrbufSubstrBeforeFirstC(version, '\n'); // Ghostty 1.1.3-arch1
593+
ffStrbufSubstrAfterFirstC(version, ' '); // 1.1.3-arch1, only Arch Linux has the suffix '-arch1'
594+
ffStrbufSubstrBeforeFirstC(version, '-'); // 1.1.3
595+
return version->length > 0;
596+
}
597+
579598
#ifndef _WIN32
580599
static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version)
581600
{
@@ -873,6 +892,9 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe
873892
if(ffStrbufStartsWithIgnCaseS(processName, "zed"))
874893
return getTerminalVersionZed(exe, version);
875894

895+
if(ffStrbufStartsWithIgnCaseS(processName, "ghostty"))
896+
return getTerminalVersionGhostty(exe, version);
897+
876898
#if __HAIKU__
877899
if(ffStrbufEqualS(processName, "Terminal"))
878900
return ffGetFileVersion(exe->chars, version);

0 commit comments

Comments
 (0)