mu: support MUHOME environment variable

This commit is contained in:
Dirk-Jan C. Binnema 2022-05-28 10:59:52 +03:00
parent 926b49220e
commit b1ff292bbb
6 changed files with 46 additions and 15 deletions

View File

@ -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.

View File

@ -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<maildir>\fR
@ -52,6 +56,8 @@ shell program, the argument may need to b quoted.
specified explicitly with \fB\-\-maildir\fR=\fI<maildir>\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

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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