unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jameson Graef Rollins <jrollins@finestructure.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 3/3] change config file location to be ~/.notmuch/config
Date: Sun, 22 Nov 2009 16:58:36 -0500	[thread overview]
Message-ID: <1258927116-528-3-git-send-email-jrollins@finestructure.net> (raw)
In-Reply-To: <1258927116-528-2-git-send-email-jrollins@finestructure.net>

This change creates a ~/.notmuch config directory where the config
file is stored when created with the "setup" command.  The use of a
~/.notmuch config directory creates one place where all notmuch config
files and data can be stored, which will greatly simplify managing
notmuch, and reduce cluter of user dot files.
---
 notmuch-config.c |   21 ++++++++++++++++++---
 notmuch-setup.c  |    2 +-
 notmuch.1        |    4 ++--
 notmuch.c        |    2 +-
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/notmuch-config.c b/notmuch-config.c
index 7252a19..321c880 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -22,9 +22,11 @@
 
 #include <pwd.h>
 #include <netdb.h>
+#include <libgen.h>
+#include <sys/stat.h>
 
 static const char toplevel_config_comment[] =
-    " .notmuch-config - Configuration file for the notmuch mail system\n"
+    " .notmuch/config - Configuration file for the notmuch mail system\n"
     "\n"
     " For more information about notmuch, see http://notmuchmail.org";
 
@@ -134,7 +136,7 @@ get_username_from_passwd_file (void *ctx)
 
 /* Open the named notmuch configuration file. A filename of NULL will
  * be interpreted as the default configuration file
- * ($HOME/.notmuch-config).
+ * ($HOME/.notmuch/config).
  *
  * If any error occurs, (out of memory, or a permission-denied error,
  * etc.), this function will print a message to stderr and return
@@ -183,7 +185,7 @@ notmuch_config_open (void *ctx,
     if (filename)
 	config->filename = talloc_strdup (config, filename);
     else
-	config->filename = talloc_asprintf (config, "%s/.notmuch-config",
+	config->filename = talloc_asprintf (config, "%s/.notmuch/config",
 					    getenv ("HOME"));
 
     config->key_file = g_key_file_new ();
@@ -297,14 +299,27 @@ notmuch_config_save (notmuch_config_t *config)
 {
     size_t length;
     char *data;
+    char buf[256];
     GError *error = NULL;
 
+    struct stat statbuf;
+
     data = g_key_file_to_data (config->key_file, &length, NULL);
     if (data == NULL) {
 	fprintf (stderr, "Out of memory.\n");
 	return 1;
     }
 
+    /* Create config directory if it doesn't already exist */
+    snprintf(buf, sizeof buf, "%s", config->filename);
+    dirname(buf);
+    if (stat(buf, &statbuf) < 0) {
+      if (mkdir(buf, 0755) < 0) {
+	fprintf (stderr, "Could not create directory '%s'\n.", buf);
+	return 1;
+      }
+    }
+
     if (! g_file_set_contents (config->filename, data, length, &error)) {
 	fprintf (stderr, "Error saving configuration to %s: %s\n",
 		 config->filename, error->message);
diff --git a/notmuch-setup.c b/notmuch-setup.c
index 68788e1..76e104c 100644
--- a/notmuch-setup.c
+++ b/notmuch-setup.c
@@ -74,7 +74,7 @@ welcome_message_post_setup (void)
 {
     printf ("\n"
 "Notmuch is now configured, and the configuration settings are saved in\n"
-"a file in your home directory named .notmuch-config . If you'd like to\n"
+"a file in your home directory named .notmuch/config . If you'd like to\n"
 "change the configuration in the future, you can either edit that file\n"
 "directly or run \"notmuch setup\".\n\n"
 
diff --git a/notmuch.1 b/notmuch.1
index 8a3fb40..9ea1d42 100644
--- a/notmuch.1
+++ b/notmuch.1
@@ -53,7 +53,7 @@ Interactively sets up notmuch for first use.
 The setup command will prompt for your full name, your primary email
 address, any alternate email addresses you use, and the directory
 containing your email archives. Your answers will be written to a
-configuration file in ${HOME}/.notmuch-config . This configuration
+configuration file in ${HOME}/.notmuch/config . This configuration
 file will be created with descriptive comments, making it easy to edit
 by hand later to change the configuration. Or you can run
 .B "notmuch setup"
@@ -245,7 +245,7 @@ takes an existing set of messages and constructs a suitable mail
 template. The Reply-to header (if any, otherwise From:) is used for
 the To: address. Vales from the To: and Cc: headers are copied, but
 not including any of the current user's email addresses (as configured
-in primary_mail or other_email in the .notmuch-config file) in the
+in primary_mail or other_email in the .notmuch/config file) in the
 recipient list
 
 It also builds a suitable new subject, including Re: at the front (if
diff --git a/notmuch.c b/notmuch.c
index 5cc8e4c..2d19a91 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -98,7 +98,7 @@ command_t commands[] = {
       "\t\tThe setup command will prompt for your full name, your primary\n"
       "\t\temail address, any alternate email addresses you use, and the\n"
       "\t\tdirectory containing your email archives. Your answers will be\n"
-      "\t\twritten to a configuration file in ${HOME}/.notmuch-config .\n"
+      "\t\twritten to a configuration file in ${HOME}/.notmuch/config .\n"
       "\n"
       "\t\tThis configuration file will be created with descriptive\n"
       "\t\tcomments, making it easy to edit by hand later to change the\n"
-- 
1.6.5

  reply	other threads:[~2009-11-22 21:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-22 21:58 [PATCH 1/3] remove Makefile.config from source to allow for custom config Jameson Graef Rollins
2009-11-22 21:58 ` [PATCH 2/3] modify notmuch_setup_command to return 1 if config file write fails Jameson Graef Rollins
2009-11-22 21:58   ` Jameson Graef Rollins [this message]
2009-11-22 22:15     ` [PATCH 3/3] change config file location to be ~/.notmuch/config Jameson Graef Rollins
2009-11-22 22:24       ` Bart Trojanowski
2009-11-22 23:14         ` Jameson Graef Rollins
2009-11-23  4:55           ` Carl Worth
2009-11-24 10:55             ` Jan Janak
2009-11-26  3:29           ` Carl Worth
2009-11-26  3:27     ` Carl Worth
2009-11-26  3:24   ` [PATCH 2/3] modify notmuch_setup_command to return 1 if config file write fails Carl Worth
2009-11-26  3:23 ` [PATCH 1/3] remove Makefile.config from source to allow for custom config Carl Worth

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=1258927116-528-3-git-send-email-jrollins@finestructure.net \
    --to=jrollins@finestructure.net \
    --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).