kernel options

This commit is contained in:
Linus Dierheimer 2021-03-07 20:35:17 +01:00
parent 6cc99423c9
commit aa5b5f3caf
6 changed files with 49 additions and 76 deletions

View File

@ -88,6 +88,8 @@ __fastfetch_completion()
"--color-logo"
"--os-architecture"
"--host-version"
"--kernel-release"
"--kernel-version"
"--shell-path"
"--battery-manufacturer"
"--battery-model"

View File

@ -30,6 +30,9 @@ void ffDefaultConfig(FFconfig* config)
config->hostShowVersion = true;
config->kernelShowRelease = true;
config->kernelShowVersion = false;
config->shellShowPath = false;
config->batteryShowManufacturer = true;

View File

@ -37,6 +37,10 @@
"## Host options:\n" \
"# --host-version true\n" \
"\n" \
"## Kernel options:\n" \
"# --kernel-release true\n" \
"# --kernel-version false\n" \
"\n" \
"## Shell options:\n" \
"# --shell-path false\n" \
"\n" \
@ -88,6 +92,10 @@ static void printHelp()
"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"
"Kernel options:\n"
" --kernel-release <?value>: Shows the release of the kernel\n"
" --kernel-version <?value>: Shows the build version of the kernel\n"
"\n"
"Shell options:\n"
" --shell-path <?value>: Show the full path of the shell\n"
"\n"
@ -145,11 +153,14 @@ static void printCommandHelp(const char* command)
static bool parseBoolean(const char* str)
{
return
if(str == NULL)
return true;
return (
strcasecmp(str, "true") == 0 ||
strcasecmp(str, "yes") == 0 ||
strcasecmp(str, "1") == 0
;
);
}
static void parseStructureCommand(FFinstance* instance, FFdata* data, const char* line)
@ -242,13 +253,6 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
puts(FASTFETCH_DEFAULT_CONFIG);
exit(0);
}
else if(strcasecmp(key, "--show-errors") == 0)
{
if(value == NULL)
instance->config.showErrors = true;
else
instance->config.showErrors = parseBoolean(value);
}
else if(strcasecmp(key, "-l") == 0 || strcasecmp(key, "--logo") == 0)
{
if(value == NULL)
@ -259,13 +263,6 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
strcpy(data->logoName, value);
}
else if(strcasecmp(key, "--color-logo") == 0)
{
if(value == NULL)
instance->config.colorLogo = true;
else
instance->config.colorLogo = parseBoolean(value);
}
else if(strcasecmp(key, "-c") == 0 || strcasecmp(key, "--color") == 0)
{
if(value == NULL)
@ -354,73 +351,33 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
else if(strcasecmp(key, "-r") == 0 || strcasecmp(key, "--recache") == 0)
{
//Set cacheSave as well, beacuse the user expects the values to be cached when expliciting using --recache
if(value == NULL)
{
instance->config.recache = true;
instance->config.cacheSave = true;
}
else
{
instance->config.recache = parseBoolean(value);
instance->config.cacheSave = instance->config.recache;
}
instance->config.recache = parseBoolean(value);
instance->config.cacheSave = instance->config.recache;
}
else if(strcasecmp(key, "--show-errors") == 0)
instance->config.showErrors = parseBoolean(value);
else if(strcasecmp(key, "--color-logo") == 0)
instance->config.colorLogo = parseBoolean(value);
else if(strcasecmp(key, "--os-architecture") == 0)
{
if(value == NULL)
instance->config.osShowArchitecture = true;
else
instance->config.osShowArchitecture = parseBoolean(value);
}
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);
}
instance->config.hostShowVersion = parseBoolean(value);
else if(strcasecmp(key, "--kernel-release") == 0)
instance->config.kernelShowRelease = parseBoolean(value);
else if(strcasecmp(key, "--kernel-version") == 0)
instance->config.kernelShowVersion = parseBoolean(value);
else if(strcasecmp(key, "--shell-path") == 0)
{
if(value == NULL)
instance->config.shellShowPath = true;
else
instance->config.shellShowPath = parseBoolean(value);
}
instance->config.shellShowPath = parseBoolean(value);
else if(strcasecmp(key, "--battery-manufacturer") == 0)
{
if(value == NULL)
instance->config.batteryShowManufacturer = true;
else
instance->config.batteryShowManufacturer = parseBoolean(value);
}
instance->config.batteryShowManufacturer = parseBoolean(value);
else if(strcasecmp(key, "--battery-model") == 0)
{
if(value == NULL)
instance->config.batteryShowModel = true;
else
instance->config.batteryShowModel = parseBoolean(value);
}
instance->config.batteryShowModel = parseBoolean(value);
else if(strcasecmp(key, "--battery-technology") == 0)
{
if(value == NULL)
instance->config.batteryShowTechnology = true;
else
instance->config.batteryShowTechnology = parseBoolean(value);
}
instance->config.batteryShowTechnology = parseBoolean(value);
else if(strcasecmp(key, "--battery-capacity") == 0)
{
if(value == NULL)
instance->config.batteryShowCapacity = true;
else
instance->config.batteryShowCapacity = parseBoolean(value);
}
instance->config.batteryShowCapacity = parseBoolean(value);
else if(strcasecmp(key, "--battery-status") == 0)
{
if(value == NULL)
instance->config.batteryShowStatus = true;
else
instance->config.batteryShowStatus = parseBoolean(value);
}
instance->config.batteryShowStatus = parseBoolean(value);
else if(strcasecmp(key, "--battery-format") == 0)
{
if(value == NULL)

View File

@ -49,6 +49,10 @@ typedef struct FFconfig
//Host
bool hostShowVersion;
//Kernel
bool kernelShowRelease;
bool kernelShowVersion;
//Shell
bool shellShowPath;

View File

@ -3,5 +3,13 @@
void ffPrintKernel(FFinstance* instance)
{
ffPrintLogoAndKey(instance, "Kernel");
puts(instance->state.utsname.release);
if(instance->config.kernelShowRelease && instance->config.kernelShowVersion)
printf("%s %s\n", instance->state.utsname.release, instance->state.utsname.version);
else if(instance->config.kernelShowRelease)
puts(instance->state.utsname.release);
else if(instance->config.kernelShowVersion)
puts(instance->state.utsname.version);
else
puts(instance->state.utsname.sysname);
}

View File

@ -1,4 +1,3 @@
rm -rf tests/build/
mkdir -p tests/build/
cd tests/build/
cmake ../.. -DBUILD_TESTS=ON