mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
--host-version
This commit is contained in:
parent
dbeaa342ba
commit
2240264d02
@ -87,6 +87,7 @@ __fastfetch_completion()
|
||||
"--show-errors"
|
||||
"--color-logo"
|
||||
"--os-architecture"
|
||||
"--host-version"
|
||||
"--shell-path"
|
||||
"--battery-manufacturer"
|
||||
"--battery-model"
|
||||
|
@ -28,6 +28,8 @@ void ffDefaultConfig(FFconfig* config)
|
||||
|
||||
config->osShowArchitecture = true;
|
||||
|
||||
config->hostShowVersion = true;
|
||||
|
||||
config->shellShowPath = false;
|
||||
|
||||
config->batteryShowManufacturer = true;
|
||||
|
@ -34,6 +34,9 @@
|
||||
"## OS options:\n" \
|
||||
"# --os-architecture true\n" \
|
||||
"\n" \
|
||||
"## Host options:\n" \
|
||||
"# --host-version true\n" \
|
||||
"\n" \
|
||||
"## Shell options:\n" \
|
||||
"# --shell-path false\n" \
|
||||
"\n" \
|
||||
@ -82,6 +85,9 @@ static void printHelp()
|
||||
"OS options:\n"
|
||||
" --os-architecture <?value>: Show the architecture of the os\n"
|
||||
"\n"
|
||||
"Host options:\n"
|
||||
" --host-version <?value>: Show the version of the host platform, if possible. Most likely, this will be the BIOS version\n"
|
||||
"\n"
|
||||
"Shell options:\n"
|
||||
" --shell-path <?value>: Show the full path of the shell\n"
|
||||
"\n"
|
||||
@ -366,6 +372,13 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
else
|
||||
instance->config.osShowArchitecture = parseBoolean(value);
|
||||
}
|
||||
else if(strcasecmp(key, "--host-version") == 0)
|
||||
{
|
||||
if(value == NULL)
|
||||
instance->config.hostShowVersion = true;
|
||||
else
|
||||
instance->config.hostShowVersion = parseBoolean(value);
|
||||
}
|
||||
else if(strcasecmp(key, "--shell-path") == 0)
|
||||
{
|
||||
if(value == NULL)
|
||||
|
@ -46,6 +46,9 @@ typedef struct FFconfig
|
||||
//OS
|
||||
bool osShowArchitecture;
|
||||
|
||||
//Host
|
||||
bool hostShowVersion;
|
||||
|
||||
//Shell
|
||||
bool shellShowPath;
|
||||
|
||||
|
@ -5,28 +5,19 @@ void ffPrintHost(FFinstance* instance)
|
||||
if(ffPrintCachedValue(instance, "Host"))
|
||||
return;
|
||||
|
||||
char host[1024];
|
||||
|
||||
FILE* nameFile = fopen("/sys/devices/virtual/dmi/id/product_name", "r");
|
||||
if(nameFile == NULL)
|
||||
char host[256];
|
||||
ffGetFileContent("/sys/devices/virtual/dmi/id/product_name", host, sizeof(host) - 32); //We subtract 32 to have at least this padding for the version
|
||||
if(host[0] == '\0')
|
||||
{
|
||||
ffPrintError(instance, "Host", "fopen(\"/sys/devices/virtual/dmi/id/product_name\", \"r\") == NULL");
|
||||
ffPrintError(instance, "Host", "ffGetFileContent(\"/sys/devices/virtual/dmi/id/product_name\", host, sizeof(host)) failed");
|
||||
return;
|
||||
}
|
||||
if(fscanf(nameFile, "%[^\n]", host) != 1)
|
||||
{
|
||||
ffPrintError(instance, "Host", "fscanf(nameFile, \"%[^\\n]\", name) != 1");
|
||||
return;
|
||||
}
|
||||
fclose(nameFile);
|
||||
|
||||
FILE* versionFile = fopen("/sys/devices/virtual/dmi/id/product_version", "r");
|
||||
if(versionFile != NULL)
|
||||
if(instance->config.hostShowVersion)
|
||||
{
|
||||
ssize_t len = strlen(host);
|
||||
host[len] = ' ';
|
||||
if(fscanf(versionFile, "%[^\n]", host + len + 1) == 0); //fail silently, if reading of version fails, just show now version
|
||||
fclose(versionFile);
|
||||
size_t len = strlen(host);
|
||||
host[len++] = ' ';
|
||||
ffGetFileContent("/sys/devices/virtual/dmi/id/product_version", host + len, sizeof(host) - len);
|
||||
}
|
||||
|
||||
ffPrintAndSaveCachedValue(instance, "Host", host);
|
||||
|
Loading…
x
Reference in New Issue
Block a user