From: Bijan Chokoufe Nejad <bijan@chokoufe.com>
To: notmuch@notmuchmail.org
Subject: [PATCH] config: Expand ~ to $HOME
Date: Sun, 8 May 2016 17:49:34 +0200 [thread overview]
Message-ID: <1462722574-4176-1-git-send-email-bijan@chokoufe.com> (raw)
Very useful in case you want to keep your .notmuch-config synchronized across
machines where you have different user names.
---
Not sure this is completely plattform independent.
I also don't know how to implement a unit test for this.
---
notmuch-config.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/notmuch-config.c b/notmuch-config.c
index d252bb2..c9f26ef 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -605,7 +605,16 @@ _config_set_list (notmuch_config_t *config,
const char *
notmuch_config_get_database_path (notmuch_config_t *config)
{
- return _config_get (config, &config->database_path, "database", "path");
+ const char* path = _config_get (config, &config->database_path, "database", "path");
+ if (path != NULL && path[0] == '~') {
+ char *home_path = getenv("HOME");
+ char *shortened_path = malloc( sizeof(char) * ( strlen (path) - 1 ) );
+ strncpy(shortened_path, path + 2, strlen(path));
+ return talloc_asprintf (NULL, "%s/%s", home_path, shortened_path);
+ }
+ else {
+ return path;
+ }
}
void
--
1.9.1
next reply other threads:[~2016-05-08 15:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-08 15:49 Bijan Chokoufe Nejad [this message]
2016-05-08 16:47 ` [PATCH] config: Expand ~ to $HOME Tomi Ollila
2016-05-08 18:50 ` Bijan Chokoufe
2016-05-09 7:54 ` Tomi Ollila
2016-05-09 8:40 ` Tomi Ollila
2016-05-09 21:57 ` Bijan Chokoufe Nejad
2016-05-10 8:22 ` David Edmondson
2016-05-11 19:17 ` Bijan Chokoufe
2016-05-11 20:11 ` David Edmondson
2016-05-11 20:16 ` Tomi Ollila
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=1462722574-4176-1-git-send-email-bijan@chokoufe.com \
--to=bijan@chokoufe.com \
--cc=notmuch@notmuchmail.org \
/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).