summaryrefslogtreecommitdiff
path: root/ted.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-07-29 15:46:13 -0400
committerpommicket <pommicket@gmail.com>2022-07-29 15:46:13 -0400
commitefce2c731927adc4aaf26d6cc6c165bbced39eb5 (patch)
tree39c4eca8347f132c413a7405c2c3ae35d0fb0903 /ted.c
parent296b4eca9479bdd1302c4b2d910f3ddd8c955fb9 (diff)
auto reload config
Diffstat (limited to 'ted.c')
-rw-r--r--ted.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/ted.c b/ted.c
index e861736..9bff01a 100644
--- a/ted.c
+++ b/ted.c
@@ -352,3 +352,38 @@ static void ted_reload_all(Ted *ted) {
menu_close(ted);
}
}
+
+// load/reload configs
+void ted_load_configs(Ted *ted) {
+ config_free(ted);
+
+ // copy global config to local config
+ char local_config_filename[TED_PATH_MAX];
+ strbuf_printf(local_config_filename, "%s" PATH_SEPARATOR_STR TED_CFG, ted->local_data_dir);
+ char global_config_filename[TED_PATH_MAX];
+ strbuf_printf(global_config_filename, "%s" PATH_SEPARATOR_STR TED_CFG, ted->global_data_dir);
+ if (!fs_file_exists(local_config_filename)) {
+ if (fs_file_exists(global_config_filename)) {
+ if (!copy_file(global_config_filename, local_config_filename)) {
+ die("Couldn't copy config %s to %s.", global_config_filename, local_config_filename);
+ }
+ } else {
+ die("ted's backup config file, %s, does not exist. Try reinstalling ted?", global_config_filename);
+ }
+ }
+
+ // read global settings
+ config_read(ted, global_config_filename, 0);
+ config_read(ted, local_config_filename, 0);
+ if (ted->search_cwd) {
+ // read config in cwd
+ config_read(ted, TED_CFG, 0);
+ }
+ // copy global settings to language-specific settings
+ for (int l = 1; l < LANG_COUNT; ++l)
+ ted->settings_by_language[l] = ted->settings_by_language[0];
+ // read language-specific settings
+ config_read(ted, global_config_filename, 1);
+ config_read(ted, local_config_filename, 1);
+ if (ted->search_cwd) config_read(ted, TED_CFG, 1);
+}