shell version support

This commit is contained in:
Linus Dierheimer
2021-04-18 15:19:21 +02:00
parent 3e9678c899
commit 1d47eb0c60
8 changed files with 117 additions and 17 deletions
+48 -8
View File
@@ -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);
}