Skip to content

Commit 2e2cf64

Browse files
committed
Terminal (Linux): add kitty version detection fast path back
1 parent 7c3835b commit 2e2cf64

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/detection/terminalshell/terminalshell.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,33 @@ static bool getTerminalVersionZed(FFstrbuf* exe, FFstrbuf* version)
485485
#ifndef _WIN32
486486
static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version)
487487
{
488+
#if defined(__linux__) || defined(__FreeBSD__)
489+
char buffer[1024] = {};
490+
if (
491+
#ifdef __linux__
492+
ffReadFileData(FASTFETCH_TARGET_DIR_USR "/lib64/kitty/kitty/constants.py", sizeof(buffer) - 1, buffer) ||
493+
ffReadFileData(FASTFETCH_TARGET_DIR_USR "/lib/kitty/kitty/constants.py", sizeof(buffer) - 1, buffer)
494+
#else
495+
ffReadFileData(_PATH_LOCALBASE "/share/kitty/kitty/constants.py", sizeof(buffer) - 1, buffer)
496+
#endif
497+
)
498+
{
499+
// Starts from version 0.17.0
500+
// https://github.com/kovidgoyal/kitty/blob/master/kitty/constants.py#L25
501+
const char* p = memmem(buffer, sizeof(buffer) - 1, "version: Version = Version(", strlen("version: Version = Version("));
502+
if (p)
503+
{
504+
p += strlen("version: Version = Version(");
505+
int major, minor, patch;
506+
if (sscanf(p, "%d,%d,%d", &major, &minor, &patch) == 3)
507+
{
508+
ffStrbufSetF(version, "%d.%d.%d", major, minor, patch);
509+
return true;
510+
}
511+
}
512+
}
513+
#endif
514+
488515
char versionHex[64];
489516
// https://github.com/fastfetch-cli/fastfetch/discussions/1030#discussioncomment-9845233
490517
if (ffGetTerminalResponse(

0 commit comments

Comments
 (0)