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

Closed
wants to merge 1 commit into from
Closed
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
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI fedora version also includes .fc42. Lets keep as it was.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

For nightly version, ghostty --version includes the branch name and commit hash.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The kernel version contains archlinux specific suffix -arch1-1. I don't think it's problematic. Do you?

ffStrbufSubstrBeforeFirstC(version, '-');
if(version->length > 0) return true;
}

if(!getExeVersionRaw(exe, version)) return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually dont think this is needed. As $TERMINAL_PROGRAM_VERSION exists.
We rely on it for some other terminals too, such as Wezterm, iTerm and warp.

Note we always add another detection method after ffBinaryExtractStrings usage, as ffBinaryExtractStrings relies on the internal implementation of terminals which is not very reliable. While $TERMINAL_PROGRAM_VERSION is considerred a public API; if the variable is not there it is a terminal bug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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)
{
@@ -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);
Loading
Oops, something went wrong.