unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Ralph Seichter <ralph@ml.seichter.de>
To: notmuch@notmuchmail.org
Cc: Ralph Seichter <ralph@seichter.de>
Subject: [PATCH] Add support for ~/foo style relative paths
Date: Tue, 29 Oct 2024 23:15:20 +0100	[thread overview]
Message-ID: <20241029221551.19393-1-ralph@ml.seichter.de> (raw)
In-Reply-To: <y220wlw.9si9p1-too@iki.fi>

In addition to the existing implicit syntax of non-absolute paths
being interpreted as relative to users' $HOME directories, also
allow the explicit syntax "~/some/relative/path". This well known
variant improves readability of configuration files.

Signed-off-by: Ralph Seichter <ralph@seichter.de>
---
 lib/config.cc | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/lib/config.cc b/lib/config.cc
index acb397ec..2537b451 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -400,15 +400,21 @@ notmuch_config_pairs_destroy (notmuch_config_pairs_t *pairs)
 static char *
 _expand_path (void *ctx, const char *key, const char *val)
 {
-    char *expanded_val;
+    char *expanded_val = NULL;
 
-    if ((strcmp (key, "database.path") == 0 ||
+    if (strcmp (key, "database.path") == 0 ||
 	 strcmp (key, "database.mail_root") == 0 ||
 	 strcmp (key, "database.hook_dir") == 0 ||
-	 strcmp (key, "database.backup_path") == 0 ) &&
-	val[0] != '/')
-	expanded_val = talloc_asprintf (ctx, "%s/%s", getenv ("HOME"), val);
-    else
+	 strcmp (key, "database.backup_path") == 0) {
+	if (val[0] == '~')
+	    /* Explicit syntax for "~/some/relative/path" */
+	    expanded_val = talloc_asprintf (ctx, "%s%s", getenv ("HOME"), &val[1]);
+	else if (val[0] != '/')
+	    /* Implicit syntax for "some/relative/path" */
+	    expanded_val = talloc_asprintf (ctx, "%s/%s", getenv ("HOME"), val);
+    }
+    if (! expanded_val)
+	/* Catchall, no special expansion */
 	expanded_val = talloc_strdup (ctx, val);
 
     return expanded_val;
-- 
2.47.0

  reply	other threads:[~2024-10-29 22:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25 22:00 Relative directories for database-mail_root and -path? Ralph Seichter
2024-10-26  2:53 ` Pengji Zhang
2024-10-26 14:49   ` Ralph Seichter
2024-10-26 17:16     ` David Bremner
2024-10-26 18:02       ` Ralph Seichter
2024-10-28  7:36         ` Tomi Ollila
2024-10-28 17:23         ` Carl Worth
2024-10-28 19:10           ` Ralph Seichter
2024-10-29  5:44             ` Tomi Ollila
2024-10-29 22:15               ` Ralph Seichter [this message]
2024-10-31 11:59                 ` [PATCH] Add support for ~/foo style relative paths David Bremner
2024-10-31 13:42                   ` Tomi Ollila
2024-10-31 20:19                   ` Ralph Seichter
2024-11-01 14:12                     ` David Bremner
2024-11-01 15:13                       ` Tomi Ollila
2024-11-01 19:57                         ` Ralph Seichter
2024-11-02 17:33                           ` Tomi Ollila
2024-11-02 19:00                             ` Ralph Seichter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241029221551.19393-1-ralph@ml.seichter.de \
    --to=ralph@ml.seichter.de \
    --cc=notmuch@notmuchmail.org \
    --cc=ralph@seichter.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).