aboutsummaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-10-20 12:43:41 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2013-10-20 12:43:41 +0200
commitd2e3a3795f345fd78ead2cf06b1134b46f9d4bc4 (patch)
treef688a32d667bc2c44ef994d4a1895911758add61 /libexec
parentdc180da2125df5eb8953ee98123ba7d73b676ff6 (diff)
downloadapp.sh-d2e3a3795f345fd78ead2cf06b1134b46f9d4bc4.tar.gz
app.sh-d2e3a3795f345fd78ead2cf06b1134b46f9d4bc4.tar.bz2
app.sh-d2e3a3795f345fd78ead2cf06b1134b46f9d4bc4.tar.xz
app.sh-d2e3a3795f345fd78ead2cf06b1134b46f9d4bc4.zip
o Getting app-cat-conf to read from ~/.appconfig too.
Diffstat (limited to 'libexec')
-rwxr-xr-xlibexec/app-cat-conf24
1 files changed, 20 insertions, 4 deletions
diff --git a/libexec/app-cat-conf b/libexec/app-cat-conf
index af382f7..ce0a3ef 100755
--- a/libexec/app-cat-conf
+++ b/libexec/app-cat-conf
@@ -11,6 +11,8 @@ APPSH_HOME=$(cd $(dirname "$0")/.. && pwd)
key_expr="[a-zA-Z][_a-zA-Z0-9]*"
files=()
+arg_files=()
+declare -a arg_files
name=""
use_default_files=yes
@@ -18,12 +20,12 @@ while getopts "f:Dn:" opt
do
case $opt in
f)
- file=$OPTARG
+ file="$OPTARG"
if [[ $file == "-" ]]
then
file=/dev/stdin
fi
- files+=($file)
+ arg_files+=($file)
;;
D)
use_default_files=no
@@ -40,12 +42,25 @@ done
if [[ $use_default_files == yes ]]
then
app_home=${APP_HOME-.}
+
+ files+=(${APPSH_DEFAULT_CONFIG-$APPSH_HOME/lib/default-config})
+
+ if [ -r "$HOME/.appconfig" ]
+ then
+ files+=("$HOME/.appconfig")
+ fi
+
if [ -r "$app_home/.app/config" ]
then
files+=("$app_home/.app/config")
fi
+fi
- files+=(${APPSH_DEFAULT_CONFIG-$APPSH_HOME/lib/default-config})
+# Even if arg_files is declared above, the files+= statement will fail
+# with "unbound" variable. bash-4.2.45.
+if [ "${#arg_files[@]}" -gt 0 ]
+then
+ files+=("${arg_files[@]}")
fi
# TODO: find config files in the paths above $file's paths and perhaps
@@ -61,7 +76,8 @@ fi
debug "Using files:" "${files[@]}"
# The awk script makes sure each key only appears once. The first one wins
-cat "${files[@]}" | \
+
+(for ((idx=${#files[@]}-1 ; idx>=0 ; idx-- )); do cat ${files[idx]}; done) | \
sed -n -e "$filter" | \
awk -F = ' (!($1 in a)){a[$1]; print }' | \
sort