From: Andre Noll Date: Thu, 20 Dec 2018 20:43:25 +0000 (+0100) Subject: Allow for more than one config file. X-Git-Url: http://git.tuebingen.mpg.de/?p=gsu.git;a=commitdiff_plain;h=8c9e5c951d304529421c11e2a7b5bc2ca145b637 Allow for more than one config file. This is easy to do, simple to implement, and backwards compatible (assuming that nobody has names of config files which contain spaces). --- diff --git a/README.md b/README.md index cb0340f..1fbcef9 100644 --- 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. +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: diff --git a/config b/config index 70a83f1..6152679 100644 --- a/config +++ b/config @@ -6,7 +6,7 @@ # file. gsu_check_options() { - local i conf="${gsu_config_file:=${HOME:-}/.$gsu_name.rc}" val orig_val + local i f 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 @@ -15,7 +15,9 @@ gsu_check_options() 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=