summaryrefslogtreecommitdiffstats
path: root/cfg.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2019-12-10 16:01:25 +0000
committerThomas Adam <thomas@xteddy.org>2019-12-10 16:01:25 +0000
commit5b2048fbb9fac8a894be52551f28b056cc7d3b66 (patch)
tree378e770de19c4aabbb4a0780ec8ff35a3620dd4d /cfg.c
parent92ecd611f68663dfceb2494e637b3ebe51d3fd86 (diff)
parent55eb3e4773b8e73d7073c53aa5a61a017631b519 (diff)
Merge branch 'obsd-master'
Diffstat (limited to 'cfg.c')
-rw-r--r--cfg.c61
1 files changed, 50 insertions, 11 deletions
diff --git a/cfg.c b/cfg.c
index c29292b2..8dbb6233 100644
--- a/cfg.c
+++ b/cfg.c
@@ -66,12 +66,45 @@ set_cfg_file(const char *path)
cfg_file = xstrdup(path);
}
+static char *
+expand_cfg_file(const char *path, const char *home)
+{
+ char *expanded, *name;
+ const char *end;
+ struct environ_entry *value;
+
+ if (strncmp(path, "~/", 2) == 0) {
+ if (home == NULL)
+ return (NULL);
+ xasprintf(&expanded, "%s%s", home, path + 1);
+ return (expanded);
+ }
+
+ if (*path == '$') {
+ end = strchr(path, '/');
+ if (end == NULL)
+ name = xstrdup(path + 1);
+ else
+ name = xstrndup(path + 1, end - path - 1);
+ value = environ_find(global_environ, name);
+ free(name);
+ if (value == NULL)
+ return (NULL);
+ if (end == NULL)
+ end = "";
+ xasprintf(&expanded, "%s%s", value->value, end);
+ return (expanded);
+ }
+
+ return (xstrdup(path));
+}
+
void
start_cfg(void)
{
- const char *home;
- int flags = 0;
+ const char *home = find_home();
struct client *c;
+ char *path, *copy, *next, *expanded;
/*
* Configuration files are loaded without a client, so commands are run
@@ -89,15 +122,21 @@ start_cfg(void)
cmdq_append(c, cfg_item);
}
- if (cfg_file == NULL)
- load_cfg(TMUX_CONF, c, NULL, CMD_PARSE_QUIET, NULL);
-
- if (cfg_file == NULL && (home = find_home()) != NULL) {
- xasprintf(&cfg_file, "%s/.tmux.conf", home);
- flags = CMD_PARSE_QUIET;
- }
- if (cfg_file != NULL)
- load_cfg(cfg_file, c, NULL, flags, NULL);
+ if (cfg_file == NULL) {
+ path = copy = xstrdup(TMUX_CONF);
+ while ((next = strsep(&path, ":")) != NULL) {
+ expanded = expand_cfg_file(next, home);
+ if (expanded == NULL) {
+ log_debug("couldn't expand %s", next);
+ continue;
+ }
+ log_debug("expanded %s to %s", next, expanded);
+ load_cfg(expanded, c, NULL, CMD_PARSE_QUIET, NULL);
+ free(expanded);
+ }
+ free(copy);
+ } else
+ load_cfg(cfg_file, c, NULL, 0, NULL);
cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
}