From 83157c02d6935d3ea4dcf6e39d6a531849a775d6 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 1 Sep 2015 10:01:56 +0000 Subject: Move initial conf load into cfg.c. --- cfg.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) (limited to 'cfg.c') diff --git a/cfg.c b/cfg.c index 37474094..e15d048d 100644 --- a/cfg.c +++ b/cfg.c @@ -23,16 +23,47 @@ #include #include #include +#include #include #include "tmux.h" -struct cmd_q *cfg_cmd_q; -int cfg_finished; -int cfg_references; -char **cfg_causes; -u_int cfg_ncauses; -struct client *cfg_client; +struct cmd_q *cfg_cmd_q; +int cfg_finished; +int cfg_references; +char **cfg_causes; +u_int cfg_ncauses; +struct client *cfg_client; + +void cfg_default_done(struct cmd_q *); + +void +start_cfg(void) +{ + char *cause = NULL; + + cfg_cmd_q = cmdq_new(NULL); + cfg_cmd_q->emptyfn = cfg_default_done; + + cfg_finished = 0; + cfg_references = 1; + + cfg_client = TAILQ_FIRST(&clients); + if (cfg_client != NULL) + cfg_client->references++; + + if (access(TMUX_CONF, R_OK) == 0) { + if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1) + cfg_add_cause("%s: %s", TMUX_CONF, cause); + } else if (errno != ENOENT) + cfg_add_cause("%s: %s", TMUX_CONF, strerror(errno)); + + if (cfg_file != NULL && load_cfg(cfg_file, cfg_cmd_q, &cause) == -1) + cfg_add_cause("%s: %s", cfg_file, cause); + free(cause); + + cmdq_continue(cfg_cmd_q); +} int load_cfg(const char *path, struct cmd_q *cmdq, char **cause) -- cgit From 952ba846111fb91d9882846a4061955262f34212 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 1 Sep 2015 10:10:59 +0000 Subject: Work out config file when needed not at startup. --- cfg.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'cfg.c') diff --git a/cfg.c b/cfg.c index e15d048d..ecb38fc0 100644 --- a/cfg.c +++ b/cfg.c @@ -28,6 +28,7 @@ #include "tmux.h" +char *cfg_file; struct cmd_q *cfg_cmd_q; int cfg_finished; int cfg_references; @@ -37,10 +38,18 @@ struct client *cfg_client; void cfg_default_done(struct cmd_q *); +void +set_cfg_file(const char *path) +{ + free(cfg_file); + cfg_file = xstrdup(path); +} + void start_cfg(void) { - char *cause = NULL; + char *cause = NULL; + const char *home; cfg_cmd_q = cmdq_new(NULL); cfg_cmd_q->emptyfn = cfg_default_done; @@ -58,6 +67,13 @@ start_cfg(void) } else if (errno != ENOENT) cfg_add_cause("%s: %s", TMUX_CONF, strerror(errno)); + if (cfg_file == NULL && (home = find_home()) != NULL) { + xasprintf(&cfg_file, "%s/.tmux.conf", home); + if (access(cfg_file, R_OK) != 0 && errno == ENOENT) { + free(cfg_file); + cfg_file = NULL; + } + } if (cfg_file != NULL && load_cfg(cfg_file, cfg_cmd_q, &cause) == -1) cfg_add_cause("%s: %s", cfg_file, cause); free(cause); -- cgit