Skip to content

TerminalShell (Linux): better support for Ghostty #1803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions src/detection/terminalshell/terminalshell.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,25 @@ static bool getTerminalVersionZed(FFstrbuf* exe, FFstrbuf* version)
return true;
}

static bool getTerminalVersionGhostty(FFstrbuf* exe, FFstrbuf* version)
{
const char* env = getenv("TERM_PROGRAM_VERSION");
if (env)
{
ffStrbufAppendS(version, env);
// 1.1.3-arch1
ffStrbufSubstrBeforeFirstC(version, '-');
if(version->length > 0) return true;
}

if(!getExeVersionRaw(exe, version)) return false;
// Ghostty 1.1.3-arch1\n\nVersion\n...
ffStrbufSubstrBeforeFirstC(version, '\n'); // Ghostty 1.1.3-arch1
ffStrbufSubstrAfterFirstC(version, ' '); // 1.1.3-arch1, only Arch Linux has the suffix '-arch1'
ffStrbufSubstrBeforeFirstC(version, '-'); // 1.1.3
return version->length > 0;
}

#ifndef _WIN32
static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version)
{
Expand Down Expand Up @@ -873,6 +892,9 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe
if(ffStrbufStartsWithIgnCaseS(processName, "zed"))
return getTerminalVersionZed(exe, version);

if(ffStrbufStartsWithIgnCaseS(processName, "ghostty"))
return getTerminalVersionGhostty(exe, version);

#if __HAIKU__
if(ffStrbufEqualS(processName, "Terminal"))
return ffGetFileVersion(exe->chars, version);
Expand Down
Loading