Merge branch 'master' into sixel

pull/3363/head
Nicholas Marriott 2019-12-10 16:34:11 +00:00
commit 1a0e5fe933
3 changed files with 54 additions and 14 deletions

View File

@ -11,7 +11,8 @@ EXTRA_DIST = \
dist_EXTRA_tmux_SOURCES = compat/*.[ch] dist_EXTRA_tmux_SOURCES = compat/*.[ch]
# Preprocessor flags. # 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. # Additional object files.
LDADD = $(LIBOBJS) LDADD = $(LIBOBJS)

61
cfg.c
View File

@ -66,12 +66,45 @@ set_cfg_file(const char *path)
cfg_file = xstrdup(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 void
start_cfg(void) start_cfg(void)
{ {
const char *home; const char *home = find_home();
int flags = 0;
struct client *c; struct client *c;
char *path, *copy, *next, *expanded;
/* /*
* Configuration files are loaded without a client, so commands are run * Configuration files are loaded without a client, so commands are run
@ -89,15 +122,21 @@ start_cfg(void)
cmdq_append(c, cfg_item); cmdq_append(c, cfg_item);
} }
if (cfg_file == NULL) if (cfg_file == NULL) {
load_cfg(TMUX_CONF, c, NULL, CMD_PARSE_QUIET, NULL); path = copy = xstrdup(TMUX_CONF);
while ((next = strsep(&path, ":")) != NULL) {
if (cfg_file == NULL && (home = find_home()) != NULL) { expanded = expand_cfg_file(next, home);
xasprintf(&cfg_file, "%s/.tmux.conf", home); if (expanded == NULL) {
flags = CMD_PARSE_QUIET; log_debug("couldn't expand %s", next);
} continue;
if (cfg_file != NULL) }
load_cfg(cfg_file, c, NULL, flags, NULL); 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)); cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
} }

4
tmux.h
View File

@ -63,9 +63,9 @@ struct winlink;
/* Client-server protocol version. */ /* Client-server protocol version. */
#define PROTOCOL_VERSION 8 #define PROTOCOL_VERSION 8
/* Default global configuration file. */ /* Default configuration files. */
#ifndef TMUX_CONF #ifndef TMUX_CONF
#define TMUX_CONF "/etc/tmux.conf" #define TMUX_CONF "/etc/tmux.conf:~/.tmux.conf"
#endif #endif
/* Minimum layout cell size, NOT including border lines. */ /* Minimum layout cell size, NOT including border lines. */