Use sysconfdir for the location of global tmux.conf (but default it to /etc),

based on changes from Dagobert Michelsen.
This commit is contained in:
Nicholas Marriott 2013-04-24 10:57:03 +01:00
parent 11b90bc959
commit 4f3c31a6b6
6 changed files with 15 additions and 15 deletions

View File

@ -15,7 +15,7 @@ dist-hook:
find $(distdir) -name .svn -type d|xargs rm -Rf find $(distdir) -name .svn -type d|xargs rm -Rf
# Preprocessor flags. # Preprocessor flags.
CPPFLAGS += @XOPEN_DEFINES@ CPPFLAGS += @XOPEN_DEFINES@ -DTMUX_CONF="\"$(sysconfdir)/tmux.conf\""
# glibc as usual does things ass-backwards and hides useful things by default, # glibc as usual does things ass-backwards and hides useful things by default,
# so everyone has to add this. # so everyone has to add this.
@ -240,9 +240,10 @@ endif
# Build tmux.1 in the right format. # Build tmux.1 in the right format.
tmux.1: tmux.1.in tmux.1: tmux.1.in
if test x@MANFORMAT@ = xmdoc; then \ if test x@MANFORMAT@ = xmdoc; then \
cp tmux.1.in tmux.1; \ sed -e "s|@SYSCONFDIR@|$(sysconfdir)|g" tmux.1.in >tmux.1; \
else \ else \
$(AWK) -fmdoc2man.awk <tmux.1.in >tmux.1; \ sed -e "s|@SYSCONFDIR@|$(sysconfdir)|g" tmux.1.in| \
$(AWK) -fmdoc2man.awk >tmux.1; \
fi fi
# Update SF web site. # Update SF web site.

View File

@ -18,6 +18,9 @@ AC_PROG_CC
AM_PROG_CC_C_O AM_PROG_CC_C_O
AC_PROG_INSTALL AC_PROG_INSTALL
# Default tmux.conf goes in /etc not ${prefix}/etc.
test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
# Check for various headers. Alternatives included from compat.h. # Check for various headers. Alternatives included from compat.h.
AC_CHECK_HEADERS( AC_CHECK_HEADERS(
[ \ [ \

View File

@ -170,13 +170,13 @@ server_start(int lockfd, char *lockfile)
cfg_references = 1; cfg_references = 1;
ARRAY_INIT(&cfg_causes); ARRAY_INIT(&cfg_causes);
if (access(SYSTEM_CFG, R_OK) == 0) { if (access(TMUX_CONF, R_OK) == 0) {
if (load_cfg(SYSTEM_CFG, cfg_cmd_q, &cause) == -1) { if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1) {
xasprintf(&cause, "%s: %s", SYSTEM_CFG, cause); xasprintf(&cause, "%s: %s", TMUX_CONF, cause);
ARRAY_ADD(&cfg_causes, cause); ARRAY_ADD(&cfg_causes, cause);
} }
} else if (errno != ENOENT) { } else if (errno != ENOENT) {
xasprintf(&cause, "%s: %s", SYSTEM_CFG, strerror(errno)); xasprintf(&cause, "%s: %s", TMUX_CONF, strerror(errno));
ARRAY_ADD(&cfg_causes, cause); ARRAY_ADD(&cfg_causes, cause);
} }
if (cfg_file != NULL) { if (cfg_file != NULL) {

View File

@ -122,7 +122,7 @@ Specify an alternative configuration file.
By default, By default,
.Nm .Nm
loads the system configuration file from loads the system configuration file from
.Pa /etc/tmux.conf , .Pa @SYSCONFDIR@/tmux.conf ,
if present, then looks for a user configuration file at if present, then looks for a user configuration file at
.Pa ~/.tmux.conf . .Pa ~/.tmux.conf .
.Pp .Pp
@ -3705,12 +3705,12 @@ was renamed to
.Ar name . .Ar name .
.El .El
.Sh FILES .Sh FILES
.Bl -tag -width "/etc/tmux.confXXX" -compact .Bl -tag -width "@SYSCONFDIR@/tmux.confXXX" -compact
.It Pa ~/.tmux.conf .It Pa ~/.tmux.conf
Default Default
.Nm .Nm
configuration file. configuration file.
.It Pa /etc/tmux.conf .It Pa @SYSCONFDIR@/tmux.conf
System-wide configuration file. System-wide configuration file.
.El .El
.Sh EXAMPLES .Sh EXAMPLES

2
tmux.c
View File

@ -363,7 +363,7 @@ main(int argc, char **argv)
if (pw != NULL) if (pw != NULL)
home = pw->pw_dir; home = pw->pw_dir;
} }
xasprintf(&cfg_file, "%s/%s", home, DEFAULT_CFG); xasprintf(&cfg_file, "%s/.tmux.conf", home);
if (access(cfg_file, R_OK) != 0 && errno == ENOENT) { if (access(cfg_file, R_OK) != 0 && errno == ENOENT) {
free(cfg_file); free(cfg_file);
cfg_file = NULL; cfg_file = NULL;

4
tmux.h
View File

@ -39,10 +39,6 @@
extern char *__progname; extern char *__progname;
extern char **environ; extern char **environ;
/* Default configuration files. */
#define DEFAULT_CFG ".tmux.conf"
#define SYSTEM_CFG "/etc/tmux.conf"
/* Default prompt history length. */ /* Default prompt history length. */
#define PROMPT_HISTORY 100 #define PROMPT_HISTORY 100