Allow for more than one config file.
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 20 Dec 2018 20:43:25 +0000 (21:43 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 24 Mar 2019 15:57:53 +0000 (16:57 +0100)
This is easy to do, simple to implement, and backwards compatible
(assuming that nobody has names of config files which contain spaces).

README.md
config

index cb0340f2540de93d94f6afef24c206c1020d9c6e..1fbcef9872ce9f5ef0ae6bb642d8a501993f448b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -651,6 +651,13 @@ following two statements are equivalent
 If an option is set both in the environment and in the config file,
 the environment takes precedence.
 
 If an option is set both in the environment and in the config file,
 the environment takes precedence.
 
+The `$gsu_config_file` variable can actually contain more than one
+filename, separated by spaces. The config files are processed in
+order, so that an option that is specified in the second config file
+overwrites the definition given in the first. This is useful for
+applications which implement a system-wide config file in addition
+to a per-user config file.
+
 ___Checking config options___
 
 The gsu config module defines two public functions for this purpose:
 ___Checking config options___
 
 The gsu config module defines two public functions for this purpose:
diff --git a/config b/config
index 70a83f1e59372765bed900ce9b9fd13dafcc7bc1..6152679d623e9b4b7873f9a92ca1c8557c301840 100644 (file)
--- a/config
+++ b/config
@@ -6,7 +6,7 @@
 # file.
 gsu_check_options()
 {
 # file.
 gsu_check_options()
 {
-       local i conf="${gsu_config_file:=${HOME:-}/.$gsu_name.rc}" val orig_val
+       local i conf="${gsu_config_file:=${HOME:-}/.$gsu_name.rc}" val orig_val
        local name option_type default_value required description help_text
 
        for ((i=0; i < ${#gsu_options[@]}; i++)); do
        local name option_type default_value required description help_text
 
        for ((i=0; i < ${#gsu_options[@]}; i++)); do
@@ -15,7 +15,9 @@ gsu_check_options()
                eval orig_${gsu_config_var_prefix}_$name='"'${val}'"'
        done
 
                eval orig_${gsu_config_var_prefix}_$name='"'${val}'"'
        done
 
-       [[ -r "$conf" ]] && source "$conf"
+       for f in $conf; do
+               [[ -r "$f" ]] && source "$f"
+       done
 
        for ((i=0; i < ${#gsu_options[@]}; i++)); do
                name=
 
        for ((i=0; i < ${#gsu_options[@]}; i++)); do
                name=