diff --git a/CMakeLists.txt b/CMakeLists.txt index b72ff5140..4695b1b1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,6 +163,7 @@ add_library(libfastfetch OBJECT src/detection/media.c src/detection/datetime.c src/detection/temps.c + src/detection/title.c src/detection/displayserver/displayServer.c src/detection/displayserver/wayland.c src/detection/displayserver/xcb.c diff --git a/completions/bash b/completions/bash index 6e5e7be2d..ca18eeb67 100644 --- a/completions/bash +++ b/completions/bash @@ -133,6 +133,7 @@ __fastfetch_completion() "--localip-show-loop" "--escape-bedrock" "--pipe" + "--title-fqdn" ) local FF_OPTIONS_STRING=( diff --git a/src/common/init.c b/src/common/init.c index 2dc0ca98e..cfa0b8e66 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -193,6 +193,8 @@ static void defaultConfig(FFinstance* instance) ffStrbufInitA(&instance->config.libOSMesa, 0); ffStrbufInitA(&instance->config.libOpenCL, 0); + instance->config.titleFQDN = false; + ffStrbufInitA(&instance->config.diskFolders, 0); ffStrbufInitA(&instance->config.batteryDir, 0); diff --git a/src/data/config_user.txt b/src/data/config_user.txt index 3bfd2bc54..7f11a4054 100644 --- a/src/data/config_user.txt +++ b/src/data/config_user.txt @@ -120,6 +120,12 @@ # Use "fastfetch --help color" to learn more and see examples. #--color magenta +# Title FQDN option: +# Sets if the title should use the fully qualified domain name. +# Must be true or false. +# Default is false. +#--title-fqdn false + # Separator option: # Sets the string placed between a key and its value. # Can be any string. diff --git a/src/data/help.txt b/src/data/help.txt index 2e672dd0e..ec4aafbc2 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -82,6 +82,7 @@ Library options: Set the path of a library to load --lib-opencl Module specific options: + --title-fqdn : sets if the title should use fully qualified domain name. Default is false. --separator-string : Set the string printed by the separator module --os-file : Set the path to the file containing OS informations --disk-folders : A colon separated list of folder paths for the disk output. Default is "/:/home" diff --git a/src/detection/title.c b/src/detection/title.c new file mode 100644 index 000000000..9961d15ba --- /dev/null +++ b/src/detection/title.c @@ -0,0 +1,37 @@ +#include "fastfetch.h" + +#include +#include +#include +#include + +const FFTitleResult* ffDetectTitle(const FFinstance* instance) +{ + static FFTitleResult result; + + static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + static bool init = false; + pthread_mutex_lock(&mutex); + if(init) + { + pthread_mutex_unlock(&mutex); + return &result; + } + init = true; + + ffStrbufInit(&result.userName); + ffStrbufAppendS(&result.userName, instance->state.passwd->pw_name); + + ffStrbufInitA(&result.hostname, HOST_NAME_MAX); + ffStrbufAppendS(&result.hostname, instance->state.utsname.nodename); + + ffStrbufInitA(&result.fqdn, HOST_NAME_MAX); + struct hostent* host = gethostbyname(result.hostname.chars); + if(host != NULL) + ffStrbufAppendS(&result.fqdn, host->h_name); + if(result.fqdn.length == 0) + ffStrbufAppend(&result.fqdn, &result.hostname); + + pthread_mutex_unlock(&mutex); + return &result; +} diff --git a/src/fastfetch.c b/src/fastfetch.c index 6a3ee7e51..44ee9109e 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1154,6 +1154,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con //Module options// ////////////////// + else if(strcasecmp(key, "--title-fqdn") == 0) + instance->config.titleFQDN = optionParseBoolean(value); else if(strcasecmp(key, "--disk-folders") == 0) optionParseString(key, value, &instance->config.diskFolders); else if(strcasecmp(key, "--battery-dir") == 0) diff --git a/src/fastfetch.h b/src/fastfetch.h index bde1aa5a7..a47779d98 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -135,6 +135,8 @@ typedef struct FFconfig FFstrbuf libOSMesa; FFstrbuf libOpenCL; + bool titleFQDN; + FFstrbuf diskFolders; FFstrbuf batteryDir; @@ -184,6 +186,7 @@ typedef struct FFTitleResult { FFstrbuf userName; FFstrbuf hostname; + FFstrbuf fqdn; //Fully qualified domain name } FFTitleResult; typedef struct FFOSResult @@ -518,6 +521,9 @@ void ffLogoBuiltinListAutocompletion(); // Detection functions // ///////////////////////// +//detection/title.c +const FFTitleResult* ffDetectTitle(const FFinstance* instance); + //detection/os.c const FFOSResult* ffDetectOS(const FFinstance* instance); @@ -552,7 +558,6 @@ const FFVulkanResult* ffDetectVulkan(const FFinstance* instance); ////////////////////// //Common -const FFTitleResult* ffDetectTitle(FFinstance* instance); void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs); diff --git a/src/modules/separator.c b/src/modules/separator.c index 51a43f839..28df99486 100644 --- a/src/modules/separator.c +++ b/src/modules/separator.c @@ -3,7 +3,8 @@ void ffPrintSeparator(FFinstance* instance) { const FFTitleResult* result = ffDetectTitle(instance); - uint32_t titleLength = result->userName.length + 1 + result->hostname.length; + uint32_t titleLength = result->userName.length + 1 + + (instance->config.titleFQDN ? result->fqdn.length : result->hostname.length); ffLogoPrintLine(instance); diff --git a/src/modules/title.c b/src/modules/title.c index 1a3a36309..95bb65337 100644 --- a/src/modules/title.c +++ b/src/modules/title.c @@ -1,33 +1,5 @@ #include "fastfetch.h" -#include -#include - -const FFTitleResult* ffDetectTitle(FFinstance* instance) -{ - static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - static bool init = false; - static FFTitleResult result; - - pthread_mutex_lock(&mutex); - if(init) - { - pthread_mutex_unlock(&mutex); - return &result; - } - init = true; - - ffStrbufInit(&result.userName); - ffStrbufAppendS(&result.userName, instance->state.passwd->pw_name); - - ffStrbufInitA(&result.hostname, 256); - gethostname(result.hostname.chars, result.hostname.allocated); - ffStrbufRecalculateLength(&result.hostname); - - pthread_mutex_unlock(&mutex); - return &result; -} - static inline void printTitlePart(FFinstance* instance, const FFstrbuf* content) { if(!instance->config.pipe) @@ -50,6 +22,6 @@ void ffPrintTitle(FFinstance* instance) printTitlePart(instance, &result->userName); putchar('@'); - printTitlePart(instance, &result->hostname); + printTitlePart(instance, instance->config.titleFQDN ? &result->fqdn : &result->hostname); putchar('\n'); }