diff --git a/CMakeLists.txt b/CMakeLists.txt index deaaad607..3a1a3a198 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,8 @@ function(fastfetch_load_text FILENAME OUTVAR) endfunction(fastfetch_load_text) fastfetch_load_text(src/data/structure.txt DATATEXT_STRUCTURE) -fastfetch_load_text(src/data/config.txt DATATEXT_CONFIG) +fastfetch_load_text(src/data/config_system.txt DATATEXT_CONFIG_SYSTEM) +fastfetch_load_text(src/data/config_user.txt DATATEXT_CONFIG_USER) fastfetch_load_text(src/data/modules.txt DATATEXT_MODULES) fastfetch_load_text(src/data/help.txt DATATEXT_HELP) fastfetch_load_text(src/data/help_color.txt DATATEXT_HELP_COLOR) @@ -495,13 +496,14 @@ endif() include(GNUInstallDirs) install( - TARGETS fastfetch + TARGETS fastfetch flashfetch DESTINATION ${CMAKE_INSTALL_BINDIR} ) install( - TARGETS flashfetch - DESTINATION ${CMAKE_INSTALL_BINDIR} + FILES src/data/config_system.txt + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/${CMAKE_PROJECT_NAME} + RENAME "config.conf" ) install( diff --git a/completions/bash b/completions/bash index 750764834..6e5e7be2d 100644 --- a/completions/bash +++ b/completions/bash @@ -108,7 +108,8 @@ __fastfetch_completion() "--list-presets" "--list-features" "--print-logos" - "--print-config" + "--print-config-system" + "--print-config-user" "--print-structure" ) diff --git a/src/data/config_system.txt b/src/data/config_system.txt new file mode 100644 index 000000000..0945399e7 --- /dev/null +++ b/src/data/config_system.txt @@ -0,0 +1,16 @@ +# Fastfetch system configuration +# This file sets the defaults for all users of the system. + +# For more information about configuration files work, +# see the file ~/.config/fastfetch/config.conf, generated during first +# All options that can be put there (or passed as argument) can be put here too. + +# This file was shipped with $"FASTFETCH_PROJECT_VERSION$". +# Use fastfetch --print-config-system > /etc/fastfetch/config.conf to overwrite this file with the current defaults + +# User config option +# Sets if fastfetch should load user provided configuration. +# If this is off, fastfetch ignores the user config file and any passed arguments +# Must be true or false +# Default is true. +#--load-user-config true diff --git a/src/data/config.txt b/src/data/config_user.txt similarity index 98% rename from src/data/config.txt rename to src/data/config_user.txt index db0d7145c..3bfd2bc54 100644 --- a/src/data/config.txt +++ b/src/data/config_user.txt @@ -6,7 +6,7 @@ # Empty lines or lines starting with # are ignored. # This file was shipped with $"FASTFETCH_PROJECT_VERSION$". -# Use fastfetch --print-config > ~/.config/fastfetch/config.conf to overwrite this with the current defaults +# Use fastfetch --print-config-user > ~/.config/fastfetch/config.conf to overwrite this file with the current defaults # Below some often usefull options are listed. Uncomment and modify them so they take affect. # Note that there are a lot more options than the ones listed here, take a look at "fastfetch --help". diff --git a/src/data/help.txt b/src/data/help.txt index 73b99aa67..2e672dd0e 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -1,16 +1,17 @@ Usage: fastfetch Informative options: - -h,--help: shows this message and exits - -h,--help : shows help for a specific command and exits - -v,--version: prints the version of fastfetch and exits - --list-logos: list available logos and exits - --list-modules: lists available modules and exits - --list-presets: list presets fastfetch knows about and exits. They can be loaded with --load-config. (+) - --list-features: list the supported features fastfetch was compiled with and exits. Mainly for development. - --print-logos: show available logos and exits - --print-config: prints the default config and exits - --print-structure: prints the default stucture and exits + -h,--help: shows this message and exits + -h,--help : shows help for a specific command and exits + -v,--version: prints the version of fastfetch and exits + --list-logos: list available logos and exits + --list-modules: lists available modules and exits + --list-presets: list presets fastfetch knows about and exits. They can be loaded with --load-config. (+) + --list-features: list the supported features fastfetch was compiled with and exits. Mainly for development. + --print-logos: show available logos and exits + --print-config-system: prints the default system config and exits + --print-config-user: prints the default user config and exits + --print-structure: prints the default stucture and exits General options: -r,--recache : generate new cached values diff --git a/src/fastfetch.c b/src/fastfetch.c index 5ba63f31d..6a3ee7e51 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -11,6 +11,7 @@ typedef struct FFdata FFvaluestore valuestore; FFstrbuf structure; bool multithreading; + bool loadUserConfig; } FFdata; static void constructAndPrintCommandHelpFormat(const char* name, const char* def, uint32_t numArgs, ...) @@ -685,9 +686,14 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con puts(FASTFETCH_PROJECT_VERSION); exit(0); } - else if(strcasecmp(key, "--print-config") == 0) + else if(strcasecmp(key, "--print-config-system") == 0) { - fputs(FASTFETCH_DATATEXT_CONFIG, stdout); + fputs(FASTFETCH_DATATEXT_CONFIG_SYSTEM, stdout); + exit(0); + } + else if(strcasecmp(key, "--print-config-user") == 0) + { + fputs(FASTFETCH_DATATEXT_CONFIG_USER, stdout); exit(0); } else if(strcasecmp(key, "--print-structure") == 0) @@ -751,6 +757,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con instance->config.escapeBedrock = optionParseBoolean(value); else if(strcasecmp(key, "--pipe") == 0) instance->config.pipe = optionParseBoolean(value); + else if(strcasecmp(key, "--load-user-config") == 0) + data->loadUserConfig = optionParseBoolean(value); //////////////// //Logo options// @@ -1198,8 +1206,21 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con } } -static void parseDefaultConfigFile(FFinstance* instance, FFdata* data) +static void parseConfigFileSystem(FFinstance* instance, FFdata* data) { + FILE* file = fopen(FASTFETCH_TARGET_DIR_ROOT"/etc/fastfetch/config.conf", "r"); + if(file == NULL) + return; + + parseConfigFile(instance, data, file); + fclose(file); +} + +static void parseConfigFileUser(FFinstance* instance, FFdata* data) +{ + if(!data->loadUserConfig) + return; + FFstrbuf* filename = ffListGet(&instance->state.configDirs, 0); uint32_t filenameLength = filename->length; @@ -1222,7 +1243,7 @@ static void parseDefaultConfigFile(FFinstance* instance, FFdata* data) file = fopen(filename->chars, "w"); if(file != NULL) { - fputs(FASTFETCH_DATATEXT_CONFIG, file); + fputs(FASTFETCH_DATATEXT_CONFIG_USER, file); fclose(file); } @@ -1231,6 +1252,9 @@ static void parseDefaultConfigFile(FFinstance* instance, FFdata* data) static void parseArguments(FFinstance* instance, FFdata* data, int argc, const char** argv) { + if(!data->loadUserConfig) + return; + for(int i = 1; i < argc; i++) { if(i == argc - 1 || ( @@ -1347,8 +1371,10 @@ int main(int argc, const char** argv) ffValuestoreInit(&data.valuestore); ffStrbufInitA(&data.structure, 256); data.multithreading = true; + data.loadUserConfig = true; - parseDefaultConfigFile(&instance, &data); + parseConfigFileSystem(&instance, &data); + parseConfigFileUser(&instance, &data); parseArguments(&instance, &data, argc, argv); //Start detection threads diff --git a/src/fastfetch_config.h.in b/src/fastfetch_config.h.in index d7bbf7fcf..bc5dde521 100644 --- a/src/fastfetch_config.h.in +++ b/src/fastfetch_config.h.in @@ -13,7 +13,8 @@ #define FASTFETCH_TARGET_DIR_HOME "@TARGET_DIR_HOME@" #define FASTFETCH_DATATEXT_STRUCTURE "@DATATEXT_STRUCTURE@" -#define FASTFETCH_DATATEXT_CONFIG "@DATATEXT_CONFIG@" //Requires FASTFETCH_PROJECT_VERSION and FASTFETCH_DATATEXT_STRUCTURE to be set +#define FASTFETCH_DATATEXT_CONFIG_SYSTEM "@DATATEXT_CONFIG_SYSTEM@" //Requires FASTFETCH_PROJECT_VERSION to be set +#define FASTFETCH_DATATEXT_CONFIG_USER "@DATATEXT_CONFIG_USER@" //Requires FASTFETCH_PROJECT_VERSION and FASTFETCH_DATATEXT_STRUCTURE to be set #define FASTFETCH_DATATEXT_MODULES "@DATATEXT_MODULES@" #define FASTFETCH_DATATEXT_HELP "@DATATEXT_HELP@" #define FASTFETCH_DATATEXT_HELP_COLOR "@DATATEXT_HELP_COLOR@"