unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] config: Expand ~ to $HOME
@ 2016-05-08 15:49 Bijan Chokoufe Nejad
  2016-05-08 16:47 ` Tomi Ollila
  0 siblings, 1 reply; 10+ messages in thread
From: Bijan Chokoufe Nejad @ 2016-05-08 15:49 UTC (permalink / raw)
  To: notmuch

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-05-11 20:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-08 15:49 [PATCH] config: Expand ~ to $HOME Bijan Chokoufe Nejad
2016-05-08 16:47 ` 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

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