mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-04 04:04:17 +01:00
shell version support
This commit is contained in:
+48
-8
@@ -1,9 +1,10 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define FF_SHELL_MODULE_NAME "Shell"
|
||||
#define FF_SHELL_NUM_FORMAT_ARGS 2
|
||||
#define FF_SHELL_NUM_FORMAT_ARGS 4
|
||||
|
||||
void ffPrintShell(FFinstance* instance)
|
||||
{
|
||||
@@ -17,28 +18,67 @@ void ffPrintShell(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
char empty[1];
|
||||
empty[0] = '\0';
|
||||
|
||||
char* shellName = strrchr(shellPath, '/');
|
||||
if(shellName != NULL)
|
||||
++shellName;
|
||||
|
||||
FFstrbuf version;
|
||||
ffStrbufInit(&version);
|
||||
|
||||
FFstrbuf command;
|
||||
ffStrbufInit(&command);
|
||||
ffStrbufAppendS(&command, "printf %s \"$");
|
||||
ffStrbufAppendTransformS(&command, shellName != NULL ? shellName : shellPath, toupper);
|
||||
ffStrbufAppendS(&command, "_VERSION\"");
|
||||
|
||||
ffProcessGetStdOut(&version, (char* const[]){
|
||||
shellPath,
|
||||
"-c",
|
||||
command.chars,
|
||||
NULL
|
||||
});
|
||||
|
||||
ffStrbufDestroy(&command);
|
||||
|
||||
FFstrbuf versionPretty;
|
||||
ffStrbufInitCopy(&versionPretty, &version);
|
||||
ffStrbufSubstrBeforeFirstC(&versionPretty, '(');
|
||||
ffStrbufRemoveStrings(&versionPretty, 1, "-release");
|
||||
|
||||
char null = '\0';
|
||||
|
||||
if(shellName == NULL)
|
||||
{
|
||||
shellName = shellPath;
|
||||
shellPath = empty;
|
||||
shellPath = &null;
|
||||
}
|
||||
else
|
||||
{
|
||||
*shellName = '\0';
|
||||
++shellName;
|
||||
*(shellName - 1) = '\0';
|
||||
}
|
||||
|
||||
FF_STRBUF_CREATE(shell);
|
||||
ffStrbufSetS(&shell, shellName);
|
||||
|
||||
if(versionPretty.length > 0)
|
||||
{
|
||||
ffStrbufAppendC(&shell, ' ');
|
||||
ffStrbufAppend(&shell, &versionPretty);
|
||||
}
|
||||
else if(version.length > 0)
|
||||
{
|
||||
ffStrbufAppendC(&shell, ' ');
|
||||
ffStrbufAppend(&shell, &version);
|
||||
}
|
||||
|
||||
ffPrintAndSaveToCache(instance, FF_SHELL_MODULE_NAME, &instance->config.shellKey, &shell, &instance->config.shellFormat, FF_SHELL_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRING, shellPath},
|
||||
{FF_FORMAT_ARG_TYPE_STRING, shellName}
|
||||
{FF_FORMAT_ARG_TYPE_STRING, shellName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &version},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &versionPretty}
|
||||
});
|
||||
|
||||
ffStrbufDestroy(&shell);
|
||||
ffStrbufDestroy(&versionPretty);
|
||||
ffStrbufDestroy(&version);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user