From 1d3a993452ac10a1c222c72693746a957179e2b6 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 2 Mar 2010 16:00:23 +0100 Subject: [PATCH] gsu: Make command line vars trump config file vars. This allows to overrule preferences given in the config file by using command line like this lv=foo snapfsck which ignores the setting of lv in ~/.snapfsck.rc and uses the value "foo" instead. --- funcs/gsu | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/funcs/gsu b/funcs/gsu index add1be4..d72f54f 100644 --- a/funcs/gsu +++ b/funcs/gsu @@ -284,14 +284,20 @@ export -f com_help # for errors and parses the config file. _gsu_check_options() { - local i conf="${gsu_config_file:=$HOME/.$gsu_name.rc}" + local i conf="${gsu_config_file:=$HOME/.$gsu_name.rc}" val + + for ((i=0; i < ${#gsu_options[@]}; i++)); do + eval "${gsu_options[$i]}" + eval val='"'\$$name'"' + eval orig_${gsu_config_var_prefix}_$name='"'${val}'"' + done [[ -r "$conf" ]] && source "$conf" for ((i=0; i < ${#gsu_options[@]}; i++)); do local name= option_type= default_value= required= local description= help_text= - local val + local val orig_val eval "${gsu_options[$i]}" @@ -305,7 +311,12 @@ _gsu_check_options() echo "$name" | grep '^[a-zA-Z][a-zA-Z_0123456789]*$' &> /dev/null; [[ $? -ne 0 ]] && return - eval val='"'\$$name'"' + eval orig_val='"'\$orig_${gsu_config_var_prefix}_$name'"' + if [[ -z "$orig_val" ]]; then + eval val='"'\$$name'"' + else + val="$orig_val" + fi case "$required" in true|yes) ret=-$E_GSU_NEED_VALUE -- 2.39.5