Files
fastfetch/src/modules/shell.c
T

49 lines
1.0 KiB
C
Raw Normal View History

2021-02-18 22:25:36 +01:00
#include "fastfetch.h"
2021-02-27 18:30:05 +01:00
void ffPrintShell(FFinstance* instance)
2021-02-18 22:25:36 +01:00
{
2021-02-27 18:30:05 +01:00
if(ffPrintCachedValue(instance, "Shell"))
2021-02-22 16:52:51 +01:00
return;
2021-02-18 22:25:36 +01:00
char* shellPath = getenv("SHELL");
2021-02-19 16:23:41 +01:00
if(shellPath == NULL)
{
2021-02-27 18:30:05 +01:00
ffPrintError(instance, "Shell", "getenv(\"SHELL\") == NULL");
2021-02-19 16:23:41 +01:00
return;
}
2021-03-19 20:57:07 +01:00
char empty[1];
empty[0] = '\0';
2021-02-18 22:25:36 +01:00
2021-03-19 20:57:07 +01:00
char* shellName = strrchr(shellPath, '/');
if(shellName == NULL)
2021-03-05 23:26:05 +01:00
{
2021-03-19 20:57:07 +01:00
shellName = shellPath;
shellPath = empty;
2021-03-05 23:26:05 +01:00
}
else
{
2021-03-19 20:57:07 +01:00
*shellName = '\0';
++shellName;
2021-03-05 23:26:05 +01:00
}
2021-02-18 22:25:36 +01:00
2021-03-19 20:57:07 +01:00
ffPrintLogoAndKey(instance, "Shell");
FFstrbuf shell;
ffStrbufInit(&shell);
if(!ffStrbufIsEmpty(&instance->config.shellFormat))
{
ffParseFormatString(&shell, &instance->config.shellFormat, 2,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, shellPath},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, shellName}
);
}
else
{
ffStrbufSetS(&shell, shellName);
}
ffPrintAndSaveCachedValue(instance, "Shell", shell.chars);
ffStrbufDestroy(&shell);
2021-02-18 22:25:36 +01:00
}