Load system config

#196
This commit is contained in:
Linus Dierheimer
2022-07-21 14:37:13 +02:00
parent f74973db65
commit 63bf22fb00
7 changed files with 69 additions and 22 deletions
+6 -4
View File
@@ -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(
+2 -1
View File
@@ -108,7 +108,8 @@ __fastfetch_completion()
"--list-presets"
"--list-features"
"--print-logos"
"--print-config"
"--print-config-system"
"--print-config-user"
"--print-structure"
)
+16
View File
@@ -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
@@ -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".
+11 -10
View File
@@ -1,16 +1,17 @@
Usage: fastfetch <options>
Informative options:
-h,--help: shows this message and exits
-h,--help <command>: 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 <command>: 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 <?value>: generate new cached values
+31 -5
View File
@@ -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
+2 -1
View File
@@ -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@"