]> git.notmuchmail.org Git - notmuch/commitdiff
Support multiple configuration files via $NOTMUCH_CONFIG
authorAlec Berryman <alec@thened.net>
Sun, 22 Nov 2009 05:18:26 +0000 (23:18 -0600)
committerCarl Worth <cworth@cworth.org>
Mon, 23 Nov 2009 02:01:57 +0000 (03:01 +0100)
If present, $NOTMUCH_CONFIG will be used as the configuration file
location.

notmuch-config.c
notmuch-setup.c
notmuch.1
notmuch.c

index aaa0372cd9bd3b4434dfe26e13d29154db260342..fc65d6b00cb1112ea59718798a3cdd2dc31be5d9 100644 (file)
@@ -132,9 +132,10 @@ get_username_from_passwd_file (void *ctx)
     return name;
 }
 
     return name;
 }
 
-/* Open the named notmuch configuration file. A filename of NULL will
- * be interpreted as the default configuration file
- * ($HOME/.notmuch-config).
+/* Open the named notmuch configuration file. If the filename is NULL,
+ * the value of the environment variable $NOTMUCH_CONFIG will be used.
+ * If $NOTMUCH_CONFIG is unset, the default configuration file
+ * ($HOME/.notmuch-config) will be used.
  *
  * If any error occurs, (out of memory, or a permission-denied error,
  * etc.), this function will print a message to stderr and return
  *
  * If any error occurs, (out of memory, or a permission-denied error,
  * etc.), this function will print a message to stderr and return
@@ -168,6 +169,7 @@ notmuch_config_open (void *ctx,
 {
     GError *error = NULL;
     int is_new = 0;
 {
     GError *error = NULL;
     int is_new = 0;
+    char *notmuch_config_env = NULL;
 
     if (is_new_ret)
        *is_new_ret = 0;
 
     if (is_new_ret)
        *is_new_ret = 0;
@@ -180,11 +182,15 @@ notmuch_config_open (void *ctx,
     
     talloc_set_destructor (config, notmuch_config_destructor);
 
     
     talloc_set_destructor (config, notmuch_config_destructor);
 
-    if (filename)
+    if (filename) {
        config->filename = talloc_strdup (config, filename);
        config->filename = talloc_strdup (config, filename);
-    else
+    } else if ((notmuch_config_env = getenv ("NOTMUCH_CONFIG"))) {
+       config->filename = talloc_strdup (config, notmuch_config_env);
+       notmuch_config_env = NULL;
+    } else {
        config->filename = talloc_asprintf (config, "%s/.notmuch-config",
                                            getenv ("HOME"));
        config->filename = talloc_asprintf (config, "%s/.notmuch-config",
                                            getenv ("HOME"));
+    }
 
     config->key_file = g_key_file_new ();
 
 
     config->key_file = g_key_file_new ();
 
index 482efd2e3b9b497fcd09089809cb4a3fcab99fc1..d06fbf80e6aac2e41e80f13abcbf7606f92a9440 100644 (file)
@@ -76,7 +76,8 @@ welcome_message_post_setup (void)
 "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"
 "change the configuration in the future, you can either edit that file\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"
 "change the configuration in the future, you can either edit that file\n"
-"directly or run \"notmuch setup\".\n\n"
+"directly or run \"notmuch setup\".  To choose an alternate configuration\n"
+"location, set ${NOTMUCH_CONFIG}.\n\n"
 
 "The next step is to run \"notmuch new\" which will create a database\n"
 "that indexes all of your mail. Depending on the amount of mail you have\n"
 
 "The next step is to run \"notmuch new\" which will create a database\n"
 "that indexes all of your mail. Depending on the amount of mail you have\n"
index 8a3fb408dc799bad933951515bc51417d824945e..eeb1a948ac8c3da69915887a8adc8578a4c1c995 100644 (file)
--- a/notmuch.1
+++ b/notmuch.1
@@ -53,9 +53,10 @@ 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
 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
-file will be created with descriptive comments, making it easy to edit
-by hand later to change the configuration. Or you can run
+configuration file in ${NOTMUCH_CONFIG} (if set) or
+${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"
 again to change the configuration.
 
 .B "notmuch setup"
 again to change the configuration.
 
index 8cb13107c6a38142c426c87085c28a5ad9fa5ecc..d84cea595202f21227ca529728bf9237cbbb576b 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -98,7 +98,8 @@ 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\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 ${NOTMUCH_CONFIG} (if set)\n"
+      "\t\tor ${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"
       "\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"