mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
TerminalShell: code refactor
This commit is contained in:
@@ -36,130 +36,119 @@ static bool getFileVersion(const char* exePath, FFstrbuf* version)
|
||||
|
||||
#endif
|
||||
|
||||
static void getShellVersionBash(FFstrbuf* exe, FFstrbuf* version)
|
||||
static bool getExeVersionRaw(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
return ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
}); // GNU bash, version 5.1.16(1)-release (x86_64-pc-msys)\nCopyright...
|
||||
}) == NULL;
|
||||
}
|
||||
|
||||
static bool getExeVersionGeneral(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
if(!getExeVersionRaw(exe, version))
|
||||
return false;
|
||||
|
||||
ffStrbufSubstrAfterFirstC(version, ' ');
|
||||
ffStrbufSubstrBeforeFirstC(version, ' ');
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool getShellVersionBash(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
if(!getExeVersionRaw(exe, version))
|
||||
return false;
|
||||
|
||||
// GNU bash, version 5.1.16(1)-release (x86_64-pc-msys)\nCopyright...
|
||||
ffStrbufSubstrBeforeFirstC(version, '\n'); // GNU bash, version 5.1.16(1)-release (x86_64-pc-msys)
|
||||
ffStrbufSubstrBeforeLastC(version, ' '); // GNU bash, version 5.1.16(1)-release
|
||||
ffStrbufSubstrAfterLastC(version, ' '); // 5.1.16(1)-release
|
||||
ffStrbufSubstrBeforeFirstC(version, '('); // 5.1.16
|
||||
return true;
|
||||
}
|
||||
|
||||
static void getShellVersionZsh(FFstrbuf* exe, FFstrbuf* version)
|
||||
static bool getShellVersionFish(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
});
|
||||
ffStrbufSubstrBeforeLastC(version, ' ');
|
||||
ffStrbufSubstrAfterFirstC(version, ' ');
|
||||
}
|
||||
if(!getExeVersionRaw(exe, version))
|
||||
return false;
|
||||
|
||||
static void getShellVersionFish(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
});
|
||||
//fish, version 3.6.0
|
||||
ffStrbufTrimRight(version, '\n');
|
||||
ffStrbufSubstrAfterLastC(version, ' ');
|
||||
return true;
|
||||
}
|
||||
|
||||
static void getShellVersionTcsh(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
}); // tcsh 6.24.01 (Astron) 2022-05-12 (aarch64-apple-darwin) options wide,nls,dl,al,kan,sm,rh,color,filec
|
||||
ffStrbufSubstrAfterFirstC(version, ' '); // 6.24.01 (Astron) 2022-05-12 (aarch64-apple-darwin) options wide,nls,dl,al,kan,sm,rh,color,filec
|
||||
ffStrbufSubstrBeforeFirstC(version, ' '); // 6.24.01
|
||||
}
|
||||
|
||||
static void getShellVersionPwsh(FFstrbuf* exe, FFstrbuf* version)
|
||||
static bool getShellVersionPwsh(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if(getFileVersion(exe->chars, version))
|
||||
return;
|
||||
{
|
||||
ffStrbufSubstrBeforeLastC(version, '.');
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
});
|
||||
if(!getExeVersionRaw(exe, version))
|
||||
return false;
|
||||
|
||||
ffStrbufTrimRight(version, '\n');
|
||||
ffStrbufSubstrAfterLastC(version, ' ');
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
static void getShellVersionWinPowerShell(FFstrbuf* exe, FFstrbuf* version)
|
||||
static bool getShellVersionWinPowerShell(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
if(ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"-NoLogo",
|
||||
"-NoProfile",
|
||||
"-Command",
|
||||
"$PSVersionTable.PSVersion.ToString()",
|
||||
NULL
|
||||
});
|
||||
})) return false;
|
||||
|
||||
ffStrbufTrimRight(version, '\n');
|
||||
ffStrbufSubstrAfterLastC(version, ' ');
|
||||
return true;
|
||||
}
|
||||
|
||||
static void getShellVersionCmd(FFstrbuf* exe, FFstrbuf* version)
|
||||
static bool getShellVersionCmd(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
getFileVersion(exe->chars, version);
|
||||
return getFileVersion(exe->chars, version);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void getShellVersionNu(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
ffProcessAppendStdOut(version, (char* const[]) {
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
});
|
||||
}
|
||||
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version)
|
||||
{
|
||||
bool ok = true;
|
||||
if(strcasecmp(exeName, "bash") == 0 || strcasecmp(exeName, "sh") == 0)
|
||||
getShellVersionBash(exe, version);
|
||||
else if(strcasecmp(exeName, "zsh") == 0)
|
||||
getShellVersionZsh(exe, version);
|
||||
else if(strcasecmp(exeName, "fish") == 0)
|
||||
getShellVersionFish(exe, version);
|
||||
else if(strcasecmp(exeName, "pwsh") == 0)
|
||||
getShellVersionPwsh(exe, version);
|
||||
else if(strcasecmp(exeName, "csh") == 0 || strcasecmp(exeName, "tcsh") == 0)
|
||||
getShellVersionTcsh(exe, version);
|
||||
else if(strcasecmp(exeName, "nu") == 0)
|
||||
getShellVersionNu(exe, version);
|
||||
return getShellVersionBash(exe, version);
|
||||
if(strcasecmp(exeName, "zsh") == 0)
|
||||
return getExeVersionGeneral(exe, version); //zsh 5.9 (arm-apple-darwin21.3.0)
|
||||
if(strcasecmp(exeName, "fish") == 0)
|
||||
return getShellVersionFish(exe, version);
|
||||
if(strcasecmp(exeName, "pwsh") == 0)
|
||||
return getShellVersionPwsh(exe, version);
|
||||
if(strcasecmp(exeName, "csh") == 0 || strcasecmp(exeName, "tcsh") == 0)
|
||||
return getExeVersionGeneral(exe, version); //tcsh 6.24.07 (Astron) 2022-12-21 (aarch64-apple-darwin) options wide,nls,dl,al,kan,sm,rh,color,filec
|
||||
if(strcasecmp(exeName, "nu") == 0)
|
||||
return getExeVersionRaw(exe, version); //0.73.0
|
||||
|
||||
#ifdef _WIN32
|
||||
else if(strcasecmp(exeName, "powershell") == 0 || strcasecmp(exeName, "powershell_ise") == 0)
|
||||
getShellVersionWinPowerShell(exe, version);
|
||||
else if(strcasecmp(exeName, "cmd") == 0)
|
||||
getShellVersionCmd(exe, version);
|
||||
if(strcasecmp(exeName, "powershell") == 0 || strcasecmp(exeName, "powershell_ise") == 0)
|
||||
return getShellVersionWinPowerShell(exe, version);
|
||||
if(strcasecmp(exeName, "cmd") == 0)
|
||||
return getShellVersionCmd(exe, version);
|
||||
#endif
|
||||
|
||||
else
|
||||
ok = false;
|
||||
return ok;
|
||||
return false;
|
||||
}
|
||||
|
||||
FF_MAYBE_UNUSED static bool getTerminalVersionTermux(FFstrbuf* version)
|
||||
{
|
||||
ffStrbufSetS(version, getenv("TERMUX_VERSION"));
|
||||
return true;
|
||||
return version->length > 0;
|
||||
}
|
||||
|
||||
FF_MAYBE_UNUSED static bool getTerminalVersionGnome(FFstrbuf* version)
|
||||
@@ -194,43 +183,7 @@ FF_MAYBE_UNUSED static bool getTerminalVersionKonsole(FFstrbuf* exe, FFstrbuf* v
|
||||
}
|
||||
}
|
||||
|
||||
if(ffProcessAppendStdOut(version, (char* const[]){
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
})) return false;
|
||||
|
||||
//konsole 22.12.1
|
||||
ffStrbufSubstrAfterFirstC(version, ' ');
|
||||
return true;
|
||||
}
|
||||
|
||||
FF_MAYBE_UNUSED static bool getTerminalVersionXfce4(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
if(ffProcessAppendStdOut(version, (char* const[]){
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
})) return false;
|
||||
|
||||
//xfce4-terminal 1.0.4 (Xfce 4.18)...
|
||||
ffStrbufSubstrAfterFirstC(version, ' ');
|
||||
ffStrbufSubstrBeforeFirstC(version, ' ');
|
||||
return true;
|
||||
}
|
||||
|
||||
FF_MAYBE_UNUSED static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version)
|
||||
{
|
||||
if(ffProcessAppendStdOut(version, (char* const[]){
|
||||
exe->chars,
|
||||
"--version",
|
||||
NULL
|
||||
})) return false;
|
||||
|
||||
//kitty 0.21.2 created by Kovid Goyal
|
||||
ffStrbufSubstrAfterFirstC(version, ' ');
|
||||
ffStrbufSubstrBeforeFirstC(version, ' ');
|
||||
return true;
|
||||
return getExeVersionGeneral(exe, version);
|
||||
}
|
||||
|
||||
bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe, FFstrbuf* version)
|
||||
@@ -251,14 +204,14 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe
|
||||
return getTerminalVersionKonsole(exe, version);
|
||||
|
||||
if(ffStrbufIgnCaseEqualS(processName, "xfce4-terminal"))
|
||||
return getTerminalVersionXfce4(exe, version);
|
||||
return getExeVersionGeneral(exe, version);//xfce4-terminal 1.0.4 (Xfce 4.18)...
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
if(ffStrbufIgnCaseEqualS(processName, "kitty"))
|
||||
return getTerminalVersionKitty(exe, version);
|
||||
return getExeVersionGeneral(exe, version); //kitty 0.21.2 created by Kovid Goyal
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user