From c4e7ae12cc5b9799edb27ffee86d3a43bce734a0 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 28 Dec 2016 22:54:37 +0000 Subject: [PATCH] sync xdg config file handling --- doc/Makefile.am | 4 +- doc/manual.xml.head | 155 +++++++++++++++++++++++++++++--------------- init.c | 22 +++++-- muttlib.c | 36 ++++++++-- 4 files changed, 155 insertions(+), 62 deletions(-) diff --git a/doc/Makefile.am b/doc/Makefile.am index 51d9c271a..9c511380f 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -218,8 +218,8 @@ smime_keys.1: $(srcdir)/smime_keys.man stamp-doc-xml: makedoc$(EXEEXT) $(top_srcdir)/init.h \ manual.xml.head $(top_srcdir)/functions.h $(top_srcdir)/OPS* manual.xml.tail \ $(srcdir)/gen-map-doc - ( date=`head -n 1 $(top_srcdir)/ChangeLog.neomutt | LC_ALL=C cut -b 1-10` && \ - sed -e "s/@VERSION\@/$(PACKAGE_VERSION) (1.7.1)/" $(srcdir)/manual.xml.head && \ + ( mutt_ver=`sed -n -e '/MUTT_VERSION/s/.*"\(.*\)".*/\1/p' $(top_srcdir)/config.h` && \ + sed -e "s/@VERSION\@/$(PACKAGE_VERSION) ($$mutt_ver)/" $(srcdir)/manual.xml.head && \ $(MAKEDOC_CPP) $(top_srcdir)/init.h | ./makedoc$(EXEEXT) -s && \ $(MAKEDOC_CPP) $(top_srcdir)/functions.h | \ perl $(srcdir)/gen-map-doc $(srcdir)/manual.xml.tail $(top_srcdir)/OPS* \ diff --git a/doc/manual.xml.head b/doc/manual.xml.head index 03d5911e9..a91e3a248 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -2349,75 +2349,126 @@ See also the $postpone quad-option. Location of Initialization Files - When Mutt starts up it looks for two configuration files -- a - system file and a user file. + When Mutt starts up it looks for two configuration files -- one + system file and one user file. - Mutt will search for a system config file in several places. The filenames - may depend on the version number of Mutt. Mutt will read just one file, the - first file it finds, from the list below. + Mutt searches for several different file names when looking for config. It + looks for NeoMutt config files before Mutt config files and versioned config + before plain config. For example: - - The system config file will not be read if the -n - option is used on the command line. - - - - Mutt system config file locations +
+ Mutt config file search order - - File Location - - $XDG_CONFIG_DIRS/neomutt/config - /etc/NeoMuttrc - /etc/Muttrc-20161104 - /etc/Muttrc - /usr/share/mutt/Muttrc-20161104 - /usr/share/mutt/Muttrc + neomuttrc-20161126 + neomuttrc + muttrc-1.7.2 + muttrc
- ($XDG_CONFIG_DIRS defaults to "/etc/xdg".) + This allows the user to create separate Mutt and NeoMutt config files on the + same system. - - Mutt will search for a user config file in several places in your home - directory. The filenames may depend on the version number of Mutt. Mutt - will read just one file, the first file it finds, from the list below. - + + Location of Mutt system config files - - You may specify your own location for the user config file using the - -F option on the command line. - + + Mutt will search for a system config file in a mutt + directory in several places. First it searches the locations specified in + the XDG_CONFIG_DIRS environment variable, which defaults + to /etc/xdg. Next, it looks in /etc. + Finally, it tries /usr/share. + - - Mutt user config file locations - - - File Location - - - $XDG_CONFIG_HOME/neomutt/config - ~/.neomuttrc - ~/.mutt/neomuttrc - ~/.muttrc-20161104 - ~/.muttrc - ~/.mutt/muttrc-20161104 - ~/.mutt/muttrc - ~/.muttrc - - -
+ + The system config file will not be read if the -n + option is used on the command line. + - - ($XDG_CONFIG_HOME defaults to "$HOME/.config".) - + + Mutt will read just one file, the first file it finds, from the list below. + + + + Mutt system config file locations + + + + File Location + Notes + + + + /etc/xdg/mutt/neomuttrc-20161126NeoMutt release version + /etc/xdg/mutt/neomuttrc + /etc/xdg/mutt/Muttrc-1.7.2Mutt release version, Note the case of the filename + /etc/xdg/mutt/MuttrcNote the case of the filename + /etc/mutt/neomuttrc-20161126NeoMutt release version + /etc/mutt/neomuttrc + /etc/mutt/Muttrc-1.7.2Mutt release version, Note the case of the filename + /etc/mutt/MuttrcNote the case of the filename + /usr/share/mutt/neomuttrc-20161126NeoMutt release version + /usr/share/mutt/neomuttrc + /usr/share/mutt/Muttrc-1.7.2Mutt release version, Note the case of the filename + /usr/share/mutt/MuttrcNote the case of the filename + + +
+
+ + + Location of Mutt system config files + + + Mutt will search for a user config file in several places. First it looks + in the directory specified in the XDG_CONFIG_HOME + environment variable, which defaults to ~/.config/mutt. + Next, it looks in ~ (your home directory). Finally, it + tries ~/.mutt. + + + + You may specify your own location for the user config file using the + -F option on the command line. + + + + Mutt will read just one file, the first file it finds, from the list below. + + + + Mutt user config file locations + + + + File Location + Notes + + + + ~/.config/mutt/neomuttrc-20161126NeoMutt release version + ~/.config/mutt/neomuttrc + ~/.config/mutt/muttrc-1.7.2Mutt release version + ~/.config/mutt/muttrc + ~/.neomuttrc-20161126NeoMutt release version + ~/.neomuttrc + ~/.muttrc-1.7.2Mutt release version + ~/.muttrc + ~/.mutt/neomuttrc-20161126NeoMutt release version + ~/.mutt/neomuttrc + ~/.mutt/muttrc-1.7.2Mutt release version + ~/.mutt/muttrc + + +
+
diff --git a/init.c b/init.c index 861834349..58e465b03 100644 --- a/init.c +++ b/init.c @@ -3426,6 +3426,8 @@ static char* mutt_find_cfg (const char *home, const char *xdg_cfg_home) { const char* names[] = { + "neomuttrc-" PACKAGE_VERSION, + "neomuttrc", "muttrc-" MUTT_VERSION, "muttrc", NULL, @@ -3433,9 +3435,9 @@ static char* mutt_find_cfg (const char *home, const char *xdg_cfg_home) const char* locations[][2] = { + { xdg_cfg_home, "mutt/", }, { home, ".", }, { home, ".mutt/" }, - { xdg_cfg_home, "mutt/", }, { NULL, NULL }, }; @@ -3736,11 +3738,15 @@ void mutt_init (int skip_sys_rc, LIST *commands) if (mutt_set_xdg_path (kXDGConfigDirs, buffer, sizeof buffer)) break; - snprintf (buffer, sizeof buffer, "%s/NeoMuttrc", SYSCONFDIR); + snprintf (buffer, sizeof buffer, "%s/neomuttrc-%s", SYSCONFDIR, PACKAGE_VERSION); + if (access (buffer, F_OK) == 0) + break; + + snprintf (buffer, sizeof buffer, "%s/neomuttrc", SYSCONFDIR); if (access (buffer, F_OK) == 0) break; - snprintf (buffer, sizeof buffer, "%s/Muttrc-%s", SYSCONFDIR, PACKAGE_VERSION); + snprintf (buffer, sizeof buffer, "%s/Muttrc-%s", SYSCONFDIR, MUTT_VERSION); if (access (buffer, F_OK) == 0) break; @@ -3748,7 +3754,15 @@ void mutt_init (int skip_sys_rc, LIST *commands) if (access (buffer, F_OK) == 0) break; - snprintf (buffer, sizeof buffer, "%s/Muttrc-%s", PKGDATADIR, PACKAGE_VERSION); + snprintf (buffer, sizeof buffer, "%s/neomuttrc-%s", PKGDATADIR, PACKAGE_VERSION); + if (access (buffer, F_OK) == 0) + break; + + snprintf (buffer, sizeof buffer, "%s/neomuttrc", PKGDATADIR); + if (access (buffer, F_OK) == 0) + break; + + snprintf (buffer, sizeof buffer, "%s/Muttrc-%s", PKGDATADIR, MUTT_VERSION); if (access (buffer, F_OK) == 0) break; diff --git a/muttlib.c b/muttlib.c index c1719337b..f482ed311 100644 --- a/muttlib.c +++ b/muttlib.c @@ -2175,21 +2175,49 @@ int mutt_set_xdg_path(const XDGType type, char *buf, size_t bufsize) char *xdg = (xdg_env && *xdg_env) ? safe_strdup (xdg_env) : safe_strdup (xdg_defaults[type]); char *x = xdg; /* strsep() changes xdg, so free x instead later */ char *token = NULL; + int rc = 0; while ((token = strsep (&xdg, ":"))) { - if (snprintf (buf, bufsize, "%s/neomutt/config", token) < 0) + if (snprintf (buf, bufsize, "%s/%s/neomuttrc-%s", token, PACKAGE, PACKAGE_VERSION) < 0) continue; mutt_expand_path (buf, bufsize); if (access (buf, F_OK) == 0) { - FREE (&x); - return 1; + rc = 1; + break; + } + + if (snprintf (buf, bufsize, "%s/%s/neomuttrc", token, PACKAGE) < 0) + continue; + mutt_expand_path (buf, bufsize); + if (access (buf, F_OK) == 0) + { + rc = 1; + break; + } + + if (snprintf (buf, bufsize, "%s/%s/Muttrc-%s", token, PACKAGE, MUTT_VERSION) < 0) + continue; + mutt_expand_path (buf, bufsize); + if (access (buf, F_OK) == 0) + { + rc = 1; + break; + } + + if (snprintf (buf, bufsize, "%s/%s/Muttrc", token, PACKAGE) < 0) + continue; + mutt_expand_path (buf, bufsize); + if (access (buf, F_OK) == 0) + { + rc = 1; + break; } } FREE (&x); - return 0; + return rc; } void mutt_get_parent_path (char *output, char *path, size_t olen) -- 2.40.0