diff --git a/src/fastfetch.c b/src/fastfetch.c index 0d8f718a9..a0f6d5729 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -253,7 +253,7 @@ static inline void printCommandHelp(const char* command) } else if(strcasecmp(command, "host-format") == 0) { - constructAndPrintCommandHelpFormat("host", "{} {} {}", 3, + constructAndPrintCommandHelpFormat("host", "{2} {3}", 3, "Host family", "Host name", "Host version" diff --git a/src/modules/host.c b/src/modules/host.c index da8f84625..f4f9a7f45 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -3,13 +3,16 @@ #define FF_HOST_MODULE_NAME "Host" #define FF_HOST_NUM_FORMAT_ARGS 3 -static inline bool hostValueSet(FFstrbuf* value) +static bool hostValueSet(FFstrbuf* value) { + ffStrbufTrim(value, ' '); + return - value != NULL && value->length > 0 && ffStrbufIgnCaseCompS(value, "None") != 0 && - ffStrbufIgnCaseCompS(value, "To be filled by O.E.M.") != 0 + ffStrbufIgnCaseCompS(value, "To be filled by O.E.M.") != 0 && + ffStrbufIgnCaseCompS(value, "System Product Name") != 0 && + ffStrbufIgnCaseCompS(value, "System Version") != 0 ; } @@ -20,14 +23,17 @@ void ffPrintHost(FFinstance* instance) FF_STRBUF_CREATE(family); ffGetFileContent("/sys/devices/virtual/dmi/id/product_family", &family); + bool familySet = hostValueSet(&family); FF_STRBUF_CREATE(name); ffGetFileContent("/sys/devices/virtual/dmi/id/product_name", &name); + bool nameSet = hostValueSet(&name); FF_STRBUF_CREATE(version); ffGetFileContent("/sys/devices/virtual/dmi/id/product_version", &version); + bool versionSet = hostValueSet(&version); - if(!hostValueSet(&family) && !hostValueSet(&name)) + if(!familySet && !nameSet) { ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &instance->config.hostKey, &instance->config.hostFormat, FF_HOST_NUM_FORMAT_ARGS, "neither family nor name is set by O.E.M."); return; @@ -35,18 +41,12 @@ void ffPrintHost(FFinstance* instance) FF_STRBUF_CREATE(host); - if(!hostValueSet(&family)) + if(nameSet) ffStrbufAppend(&host, &name); - else if(!hostValueSet(&name)) - ffStrbufAppend(&host, &family); else - { ffStrbufAppend(&host, &family); - ffStrbufAppendC(&host, ' '); - ffStrbufAppend(&host, &name); - } - if(hostValueSet(&version)) { + if(versionSet) { ffStrbufAppendC(&host, ' '); ffStrbufAppend(&host, &version); }