summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2019-12-10 16:34:11 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2019-12-10 16:34:11 +0000
commit1a0e5fe933e89932f2f658936c52eb50644fbef4 (patch)
tree715b29a7a9c2762d11eaeb268f0ee04c0e553f78
parentcf071ffecd5a0d33008fd0a8b66a22f6855c7a8d (diff)
parent15d7e564ddab575dd3ac803989cc99ac13b57198 (diff)
Merge branch 'master' into sixel
-rw-r--r--Makefile.am3
-rw-r--r--cfg.c61
-rw-r--r--tmux.h4
3 files changed, 54 insertions, 14 deletions
diff --git a/Makefile.am b/Makefile.am
index 5e8c75ba..40aa8705 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,7 +11,8 @@ EXTRA_DIST = \
dist_EXTRA_tmux_SOURCES = compat/*.[ch]
# Preprocessor flags.
-AM_CPPFLAGS += @XOPEN_DEFINES@ -DTMUX_CONF="\"$(sysconfdir)/tmux.conf\""
+AM_CPPFLAGS += @XOPEN_DEFINES@
+AM_CPPFLAGS += -DTMUX_CONF="\"$(sysconfdir)/tmux.conf:~/.tmux.conf:~/.config/tmux/tmux.conf\""
# Additional object files.
LDADD = $(LIBOBJS)
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));
}
diff --git a/tmux.h b/tmux.h
index 79c08491..288db687 100644
--- a/tmux.h
+++ b/tmux.h
@@ -63,9 +63,9 @@ struct winlink;
/* Client-server protocol version. */
#define PROTOCOL_VERSION 8
-/* Default global configuration file. */
+/* Default configuration files. */
#ifndef TMUX_CONF
-#define TMUX_CONF "/etc/tmux.conf"
+#define TMUX_CONF "/etc/tmux.conf:~/.tmux.conf"
#endif
/* Minimum layout cell size, NOT including border lines. */