diff --git a/NEWS.org b/NEWS.org index 91b66dc5..0f27bd15 100644 --- a/NEWS.org +++ b/NEWS.org @@ -53,6 +53,9 @@ much of this is not immediately visible but is an enabler for some new features. + - instead of passing ~--muhome~, you can now also set an environment variable + ~MUHOME~. + - the ~info~ command now includes information about the last indexing operation and the last database change that took place; note that the information may be slightly delayed due to database caching. diff --git a/man/mu-init.1 b/man/mu-init.1 index 27309e8b..e5697d49 100644 --- a/man/mu-init.1 +++ b/man/mu-init.1 @@ -1,4 +1,4 @@ -.TH MU-INIT 1 "January 2022" "User Manuals" +.TH MU-INIT 1 "May 2022" "User Manuals" .SH NAME @@ -23,8 +23,12 @@ man-page and not here, as they apply to multiple mu commands. \fB\-\-muhome\fR use an alternative directory to store and read the database, write the logs, etc. By default, \fBmu\fR uses XDG Base Directory Specification (e.g. on Linux -this defaults to \fI~/.cache/mu\fR, \fI~/.config/mu\fR). Earlier versions of -\fBmu\fR defaulted to \fI~/.mu\fR, which now requires \fI\-\-muhome=~/.mu\fR. +this defaults to \fI~/.cache/mu\fR, \fI~/.config/mu\fR). + +Earlier versions of \fBmu\fR defaulted to \fI~/.mu\fR, which now requires +\fI\-\-muhome=~/.mu\fR. + +Alternatively, use can use the \fBMUHOME\fR environment variable (the command-line takes precedence). .TP \fB\-m\fR, \fB\-\-maildir\fR=\fI\fR @@ -52,6 +56,8 @@ shell program, the argument may need to b quoted. specified explicitly with \fB\-\-maildir\fR=\fI\fR. If \fBMAILDIR\fR is not set, \fBmu init\fR uses \fI~/Maildir\fR. +\fBMUHOME\fR can be used as an alternative to \fB\-\-muhome\fR. + .SH RETURN VALUE \fBmu init\fR returns 0 upon successful completion, or a non-zero exit code if diff --git a/man/mu.1 b/man/mu.1 index c6a9063f..95469e99 100644 --- a/man/mu.1 +++ b/man/mu.1 @@ -1,4 +1,4 @@ -.TH MU 1 "February 2021" "User Manuals" +.TH MU 1 "May 2022" "User Manuals" .SH NAME @@ -162,6 +162,12 @@ prints \fBmu\fR version and copyright information. \fB\-h\fR, \fB\-\-help\fR lists the various command line options. +.SH ENVIRONMENT + +\fBMUHOME\fR can be used as an alternative to \fB\-\-muhome\fR. The latter has precedence. + +\fBNO_COLOR\fR can be used as an alternative to \fB\-\-nocolor\fR. + .SH ERROR CODES The various mu subcommands typically exit with 0 (zero) upon success, and diff --git a/mu/mu-config.cc b/mu/mu-config.cc index 348c5eeb..f42b4149 100644 --- a/mu/mu-config.cc +++ b/mu/mu-config.cc @@ -75,8 +75,17 @@ get_output_format(const char* formatstr) static void set_group_mu_defaults() { - /* If muhome is not set, we use the XDG Base Directory Specification - * locations. */ + /* try to determine muhome from command-line or environment; + * note: if not specified, we use XDG defaults */ + + if (!MU_CONFIG.muhome) { + /* if not set explicity, try the environment */ + const char* muhome; + muhome = g_getenv("MUHOME"); + if (muhome) + MU_CONFIG.muhome = g_strdup(muhome); + } + if (MU_CONFIG.muhome) expand_dir(MU_CONFIG.muhome); diff --git a/mu/tests/test-mu-query.cc b/mu/tests/test-mu-query.cc index 26d0000d..ca2b73a6 100644 --- a/mu/tests/test-mu-query.cc +++ b/mu/tests/test-mu-query.cc @@ -45,14 +45,16 @@ static std::string make_database(const std::string& testdir) { char* tmpdir{test_mu_common_get_random_tmpdir()}; + + /* use the env var rather than `--muhome` */ + + g_setenv("MUHOME", tmpdir, 1); const auto cmdline{format("/bin/sh -c '" - "%s init --muhome=%s --maildir=%s --quiet ; " - "%s index --muhome=%s --quiet'", + "%s init --maildir=%s --quiet ; " + "%s index --quiet'", MU_PROGRAM, - tmpdir, testdir.c_str(), - MU_PROGRAM, - tmpdir)}; + MU_PROGRAM)}; if (g_test_verbose()) g_printerr("\n%s\n", cmdline.c_str()); @@ -61,6 +63,9 @@ make_database(const std::string& testdir) auto xpath = g_strdup_printf("%s%c%s", tmpdir, G_DIR_SEPARATOR, "xapian"); g_free(tmpdir); + /* ensure MUHOME worked */ + g_assert_cmpuint(::access(xpath, F_OK), ==, 0); + std::string dbpath{xpath}; g_free(xpath); diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index 6e40fab0..47a0f66f 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -401,9 +401,10 @@ different file-systems; and symbolic links are supported. @section Initializing the message store The first time you run @t{mu}, you need to initialize its store -(database). The default location for that is @t{~/.cache/mu/xapian}, -but you can change this using the @t{--muhome} option, and remember to -pass that to the other commands as well. +(database). The default location for that is @t{~/.cache/mu/xapian}, but +you can change this using the @t{--muhome} option, and remember to pass +that to the other commands as well. Alternatively, you can use an +environment variable @t{MUHOME}. Assuming that your maildir is at @file{~/Maildir}, we issue the following command: @@ -428,7 +429,8 @@ slashes, for example: $ mu init --maildir=~/Maildir '--my-address=/foo-.*@@example\.com/' @end example -If you want to see the current values, you can use @command{mu info}. +If you want to see the values for your message-store, you can use +@command{mu info}. @node Indexing your messages @section Indexing your messages