mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
--host-format
This commit is contained in:
parent
8e9cb079b0
commit
37dd06590a
@ -4,9 +4,10 @@ __fastfetch_complete_help()
|
|||||||
{
|
{
|
||||||
local __ff_helps=(
|
local __ff_helps=(
|
||||||
"color"
|
"color"
|
||||||
"battery-format"
|
|
||||||
"packages-format"
|
|
||||||
"os-format"
|
"os-format"
|
||||||
|
"host-format"
|
||||||
|
"packages-format"
|
||||||
|
"battery-format"
|
||||||
)
|
)
|
||||||
COMPREPLY=($(compgen -W "${__ff_helps[*]}" -- "$CURRENT_WORD"))
|
COMPREPLY=($(compgen -W "${__ff_helps[*]}" -- "$CURRENT_WORD"))
|
||||||
}
|
}
|
||||||
@ -120,6 +121,7 @@ __fastfetch_completion()
|
|||||||
"-x"
|
"-x"
|
||||||
"--offsetx"
|
"--offsetx"
|
||||||
"--os-format"
|
"--os-format"
|
||||||
|
"--host-format"
|
||||||
"--packages-format"
|
"--packages-format"
|
||||||
"--resolution-format"
|
"--resolution-format"
|
||||||
"--battery-format"
|
"--battery-format"
|
||||||
|
@ -32,6 +32,7 @@ void ffDefaultConfig(FFconfig* config)
|
|||||||
config->osFormat[0] = '\0';
|
config->osFormat[0] = '\0';
|
||||||
|
|
||||||
config->hostShowVersion = true;
|
config->hostShowVersion = true;
|
||||||
|
config->hostFormat[0] = '\0';
|
||||||
|
|
||||||
config->kernelShowRelease = true;
|
config->kernelShowRelease = true;
|
||||||
config->kernelShowVersion = false;
|
config->kernelShowVersion = false;
|
||||||
|
@ -103,6 +103,7 @@ static inline void printHelp()
|
|||||||
"\n"
|
"\n"
|
||||||
"Host options:\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"
|
" --host-version <?value>: Show the version of the host platform, if possible. Most likely, this will be the BIOS version\n"
|
||||||
|
" --host-format <format>: Provide the printf format string for host output (+)\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Kernel options:\n"
|
"Kernel options:\n"
|
||||||
" --kernel-release <?value>: Shows the release of the kernel\n"
|
" --kernel-release <?value>: Shows the release of the kernel\n"
|
||||||
@ -166,6 +167,19 @@ static inline void printCommandHelpOsFormat()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void printCommandHelpHostFormat()
|
||||||
|
{
|
||||||
|
puts(
|
||||||
|
"usage fastfetch --host-format <format>\n"
|
||||||
|
"\n"
|
||||||
|
"<format> is a string of maximum length 32, which is passed to printf as the format string.\n"
|
||||||
|
"The arguments passed to printf are 3 strings in following order:\n"
|
||||||
|
"family, name, version\n"
|
||||||
|
"If an value could not be determined, it will be an zero length string.\n"
|
||||||
|
"The default value is something like \"%s %s %s\"."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void printCommandHelpBatteryFormat()
|
static inline void printCommandHelpBatteryFormat()
|
||||||
{
|
{
|
||||||
puts(
|
puts(
|
||||||
@ -211,6 +225,8 @@ static inline void printCommandHelp(const char* command)
|
|||||||
printCommandHelpColor();
|
printCommandHelpColor();
|
||||||
else if(strcasecmp(command, "os-format") == 0)
|
else if(strcasecmp(command, "os-format") == 0)
|
||||||
printCommandHelpOsFormat();
|
printCommandHelpOsFormat();
|
||||||
|
else if(strcasecmp(command, "host-format") == 0)
|
||||||
|
printCommandHelpHostFormat();
|
||||||
else if(strcasecmp(command, "battery-format") == 0)
|
else if(strcasecmp(command, "battery-format") == 0)
|
||||||
printCommandHelpBatteryFormat();
|
printCommandHelpBatteryFormat();
|
||||||
else if(strcasecmp(command, "packages-format") == 0)
|
else if(strcasecmp(command, "packages-format") == 0)
|
||||||
@ -424,6 +440,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
|||||||
optionParseString(key, value, instance->config.osFormat, sizeof(instance->config.osFormat));
|
optionParseString(key, value, instance->config.osFormat, sizeof(instance->config.osFormat));
|
||||||
else if(strcasecmp(key, "--host-version") == 0)
|
else if(strcasecmp(key, "--host-version") == 0)
|
||||||
instance->config.hostShowVersion = optionParseBoolean(value);
|
instance->config.hostShowVersion = optionParseBoolean(value);
|
||||||
|
else if(strcasecmp(key, "--host-format") == 0)
|
||||||
|
optionParseString(key, value, instance->config.hostFormat, sizeof(instance->config.hostFormat));
|
||||||
else if(strcasecmp(key, "--kernel-release") == 0)
|
else if(strcasecmp(key, "--kernel-release") == 0)
|
||||||
instance->config.kernelShowRelease = optionParseBoolean(value);
|
instance->config.kernelShowRelease = optionParseBoolean(value);
|
||||||
else if(strcasecmp(key, "--kernel-version") == 0)
|
else if(strcasecmp(key, "--kernel-version") == 0)
|
||||||
|
@ -49,6 +49,7 @@ typedef struct FFconfig
|
|||||||
|
|
||||||
//Host
|
//Host
|
||||||
bool hostShowVersion;
|
bool hostShowVersion;
|
||||||
|
char hostFormat[32];
|
||||||
|
|
||||||
//Kernel
|
//Kernel
|
||||||
bool kernelShowRelease;
|
bool kernelShowRelease;
|
||||||
|
@ -5,19 +5,39 @@ void ffPrintHost(FFinstance* instance)
|
|||||||
if(ffPrintCachedValue(instance, "Host"))
|
if(ffPrintCachedValue(instance, "Host"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char host[256];
|
char family[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
|
ffGetFileContent("/sys/devices/virtual/dmi/id/product_family", family, sizeof(family));
|
||||||
if(host[0] == '\0')
|
|
||||||
{
|
|
||||||
ffPrintError(instance, "Host", "ffGetFileContent(\"/sys/devices/virtual/dmi/id/product_name\", host, sizeof(host)) failed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(instance->config.hostShowVersion)
|
char name[256];
|
||||||
|
ffGetFileContent("/sys/devices/virtual/dmi/id/product_name", name, sizeof(name));
|
||||||
|
|
||||||
|
char version[256];
|
||||||
|
if(instance->config.hostShowVersion || instance->config.hostFormat[0] != '\0')
|
||||||
|
ffGetFileContent("/sys/devices/virtual/dmi/id/product_version", version, sizeof(version));
|
||||||
|
else
|
||||||
|
version[0] = '\0';
|
||||||
|
|
||||||
|
char host[1024];
|
||||||
|
|
||||||
|
if(instance->config.hostFormat[0] != '\0')
|
||||||
{
|
{
|
||||||
size_t len = strlen(host);
|
snprintf(host, sizeof(host), instance->config.hostFormat, family, name, version);
|
||||||
host[len++] = ' ';
|
}
|
||||||
ffGetFileContent("/sys/devices/virtual/dmi/id/product_version", host + len, sizeof(host) - len);
|
else if(family[0] == '\0' && name[0] == '\0')
|
||||||
|
{
|
||||||
|
ffPrintError(instance, "Host", "neither family nor name could be determined");
|
||||||
|
return;
|
||||||
|
}else if(family[0] != '\0' && name[0] != '\0')
|
||||||
|
{
|
||||||
|
snprintf(host, sizeof(host), "%s %s %s", family, name, instance->config.hostShowVersion ? version : "");
|
||||||
|
}
|
||||||
|
else if(family[0] != '\0')
|
||||||
|
{
|
||||||
|
snprintf(host, sizeof(host), "%s %s", family, instance->config.hostShowVersion ? version : "");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(host, sizeof(host), "%s %s", name, instance->config.hostShowVersion ? version : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
ffPrintAndSaveCachedValue(instance, "Host", host);
|
ffPrintAndSaveCachedValue(instance, "Host", host);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user