From aa5b5f3caf7182bb082741d948a54b9dde117c8f Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sun, 7 Mar 2021 20:35:17 +0100 Subject: [PATCH] kernel options --- completions/bash | 2 + src/common.c | 3 ++ src/fastfetch.c | 105 +++++++++++++------------------------------ src/fastfetch.h | 4 ++ src/modules/kernel.c | 10 ++++- tests/performance.sh | 1 - 6 files changed, 49 insertions(+), 76 deletions(-) diff --git a/completions/bash b/completions/bash index 5cfc15d3..7f0df66f 100644 --- a/completions/bash +++ b/completions/bash @@ -88,6 +88,8 @@ __fastfetch_completion() "--color-logo" "--os-architecture" "--host-version" + "--kernel-release" + "--kernel-version" "--shell-path" "--battery-manufacturer" "--battery-model" diff --git a/src/common.c b/src/common.c index d15905f6..f5c6c787 100644 --- a/src/common.c +++ b/src/common.c @@ -30,6 +30,9 @@ void ffDefaultConfig(FFconfig* config) config->hostShowVersion = true; + config->kernelShowRelease = true; + config->kernelShowVersion = false; + config->shellShowPath = false; config->batteryShowManufacturer = true; diff --git a/src/fastfetch.c b/src/fastfetch.c index 1ed8258e..6ae5d40f 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -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 : Show the version of the host platform, if possible. Most likely, this will be the BIOS version\n" "\n" + "Kernel options:\n" + " --kernel-release : Shows the release of the kernel\n" + " --kernel-version : Shows the build version of the kernel\n" + "\n" "Shell options:\n" " --shell-path : 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) diff --git a/src/fastfetch.h b/src/fastfetch.h index 32044fbf..a8177b52 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -49,6 +49,10 @@ typedef struct FFconfig //Host bool hostShowVersion; + //Kernel + bool kernelShowRelease; + bool kernelShowVersion; + //Shell bool shellShowPath; diff --git a/src/modules/kernel.c b/src/modules/kernel.c index 79b5f737..18818c99 100644 --- a/src/modules/kernel.c +++ b/src/modules/kernel.c @@ -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); } \ No newline at end of file diff --git a/tests/performance.sh b/tests/performance.sh index 365b0165..4a175e58 100755 --- a/tests/performance.sh +++ b/tests/performance.sh @@ -1,4 +1,3 @@ -rm -rf tests/build/ mkdir -p tests/build/ cd tests/build/ cmake ../.. -DBUILD_TESTS=ON