Files
fastfetch/src/modules/shell.c
T

49 lines
1.1 KiB
C
Raw Normal View History

2021-02-18 22:25:36 +01:00
#include "fastfetch.h"
2021-04-09 14:07:05 +02:00
#include <string.h>
2021-02-27 18:30:05 +01:00
void ffPrintShell(FFinstance* instance)
2021-02-18 22:25:36 +01:00
{
2021-04-03 11:39:59 +02:00
if(ffPrintCachedValue(instance, &instance->config.shellKey, "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-04-03 11:39:59 +02:00
ffPrintError(instance, &instance->config.shellKey, "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
FF_STRBUF_CREATE(shell);
2021-03-19 20:57:07 +01:00
2021-03-23 19:48:52 +01:00
if(instance->config.shellFormat.length == 0)
{
ffStrbufSetS(&shell, shellName);
}
else
2021-03-19 20:57:07 +01:00
{
ffParseFormatString(&shell, &instance->config.shellFormat, 2,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, shellPath},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, shellName}
);
}
2021-04-03 11:39:59 +02:00
ffPrintAndSaveCachedValue(instance, &instance->config.shellKey, "Shell", &shell);
2021-03-19 20:57:07 +01:00
ffStrbufDestroy(&shell);
2021-03-27 18:14:19 +01:00
}