mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-02 03:14:15 +01:00
TerminalShell: uses absolute path when detecting version if available
Closes #2067
This commit is contained in:
@@ -273,6 +273,10 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
|
||||
ffStrbufEnsureFixedLengthFree(exePath, (uint32_t)length);
|
||||
ffStrbufAppendNS(exePath, (uint32_t)length, buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffStrbufSetS(exePath, filePath);
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
@@ -64,12 +64,9 @@ static bool extractBashVersion(const char* line, FF_MAYBE_UNUSED uint32_t len, v
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool getShellVersionBash(FFstrbuf* exe, FFstrbuf* exePath, FFstrbuf* version)
|
||||
static bool getShellVersionBash(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
const char* path = exePath->chars;
|
||||
if (*path == '\0')
|
||||
path = exe->chars;
|
||||
ffBinaryExtractStrings(path, extractBashVersion, version, (uint32_t) strlen("@(#)Bash version 0.0.0(0) release GNU"));
|
||||
ffBinaryExtractStrings(exe->chars, extractBashVersion, version, (uint32_t) strlen("@(#)Bash version 0.0.0(0) release GNU"));
|
||||
if (version->length > 0) return true;
|
||||
|
||||
if(!getExeVersionRaw(exe, version))
|
||||
@@ -230,13 +227,9 @@ static bool extractZshVersion(const char* line, FF_MAYBE_UNUSED uint32_t len, vo
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool getShellVersionZsh(FFstrbuf* exe, FFstrbuf* exePath, FFstrbuf* version)
|
||||
static bool getShellVersionZsh(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
const char* path = exePath->chars;
|
||||
if (*path == '\0')
|
||||
path = exe->chars;
|
||||
|
||||
ffBinaryExtractStrings(path, extractZshVersion, version, (uint32_t) strlen("zsh-0.0-0"));
|
||||
ffBinaryExtractStrings(exe->chars, extractZshVersion, version, (uint32_t) strlen("zsh-0.0-0"));
|
||||
if (version->length) return true;
|
||||
|
||||
return getExeVersionGeneral(exe, version); //zsh 5.9 (arm-apple-darwin21.3.0)
|
||||
@@ -263,7 +256,7 @@ static bool getShellVersionWinPowerShell(FFstrbuf* exe, FFstrbuf* version)
|
||||
}
|
||||
#endif
|
||||
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* exePath, FFstrbuf* version)
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version)
|
||||
{
|
||||
if (!instance.config.general.detectVersion) return false;
|
||||
|
||||
@@ -271,9 +264,9 @@ bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* exePath,
|
||||
return false;
|
||||
|
||||
if(ffStrEqualsIgnCase(exeName, "bash"))
|
||||
return getShellVersionBash(exe, exePath, version);
|
||||
return getShellVersionBash(exe, version);
|
||||
if(ffStrEqualsIgnCase(exeName, "zsh"))
|
||||
return getShellVersionZsh(exe, exePath, version);
|
||||
return getShellVersionZsh(exe, version);
|
||||
if(ffStrEqualsIgnCase(exeName, "fish"))
|
||||
return getShellVersionFish(exe, version);
|
||||
if(ffStrEqualsIgnCase(exeName, "pwsh"))
|
||||
|
||||
@@ -292,14 +292,14 @@ static void getUserShellFromEnv(FFShellResult* result)
|
||||
}
|
||||
}
|
||||
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* exePath, FFstrbuf* version);
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version);
|
||||
|
||||
bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* version);
|
||||
|
||||
static void setShellInfoDetails(FFShellResult* result)
|
||||
{
|
||||
ffStrbufClear(&result->version);
|
||||
fftsGetShellVersion(&result->exe, result->exeName, &result->exePath, &result->version);
|
||||
fftsGetShellVersion(result->exePath.length > 0 ? &result->exePath : &result->exe, result->exeName, &result->version);
|
||||
|
||||
if(ffStrbufEqualS(&result->processName, "pwsh"))
|
||||
ffStrbufInitStatic(&result->prettyName, "PowerShell");
|
||||
@@ -383,7 +383,7 @@ static void setTerminalInfoDetails(FFTerminalResult* result)
|
||||
else
|
||||
ffStrbufInitCopy(&result->prettyName, &result->processName);
|
||||
|
||||
fftsGetTerminalVersion(&result->processName, &result->exe, &result->version);
|
||||
fftsGetTerminalVersion(&result->processName, result->exePath.length > 0 ? &result->exePath : &result->exe, &result->version);
|
||||
}
|
||||
|
||||
#if defined(MAXPATH)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <wchar.h>
|
||||
#include <tlhelp32.h>
|
||||
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, const FFstrbuf* exePath, FFstrbuf* version);
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version);
|
||||
|
||||
static uint32_t getShellInfo(FFShellResult* result, uint32_t pid)
|
||||
{
|
||||
@@ -332,7 +332,7 @@ const FFShellResult* ffDetectShell(void)
|
||||
strcpy(tmp, result.exeName);
|
||||
char* ext = strrchr(tmp, '.');
|
||||
if (ext) *ext = '\0';
|
||||
fftsGetShellVersion(&result.exe, tmp, &result.exePath, &result.version);
|
||||
fftsGetShellVersion(result.exePath.length > 0 ? &result.exePath : &result.exe, tmp, &result.version);
|
||||
}
|
||||
|
||||
return &result;
|
||||
@@ -368,7 +368,7 @@ const FFTerminalResult* ffDetectTerminal(void)
|
||||
if(result.processName.length > 0)
|
||||
{
|
||||
setTerminalInfoDetails(&result);
|
||||
fftsGetTerminalVersion(&result.processName, &result.exe, &result.version);
|
||||
fftsGetTerminalVersion(&result.processName, result.exePath.length > 0 ? &result.exePath : &result.exe, &result.version);
|
||||
}
|
||||
|
||||
return &result;
|
||||
|
||||
Reference in New Issue
Block a user