From 13cf157703a199d264d65295407b89242554886e Mon Sep 17 00:00:00 2001 From: apocelipes Date: Tue, 17 Jun 2025 16:45:58 +0800 Subject: [PATCH] TerminalShell (Linux): better support for Ghostty --- src/detection/terminalshell/terminalshell.c | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index d8cc0cd7ea..0bec23eb49 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -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) { @@ -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);