aboutsummaryrefslogtreecommitdiff
path: root/libexec/app-cat-conf
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-01-26 23:58:22 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2013-01-26 23:58:22 +0100
commit110ffae47db27a49bbc43f86ba3737bccc1b3085 (patch)
treed74934b12e2904b8aff5fe87421a6501b8ea5c8e /libexec/app-cat-conf
parentca27d6f6d9ccc35bf55db3d360d1d464d5e206e7 (diff)
downloadapp.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.tar.gz
app.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.tar.bz2
app.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.tar.xz
app.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.zip
o Rewriting most of this stuff to make it feel more like git.
Diffstat (limited to 'libexec/app-cat-conf')
-rwxr-xr-xlibexec/app-cat-conf47
1 files changed, 47 insertions, 0 deletions
diff --git a/libexec/app-cat-conf b/libexec/app-cat-conf
new file mode 100755
index 0000000..78d3c36
--- /dev/null
+++ b/libexec/app-cat-conf
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+if [[ $APPSH_HOME == "" ]]
+then
+ APPSH_HOME=`dirname "$0"`
+ APPSH_HOME=`cd "$APPSH_HOME/.." && pwd`
+fi
+
+set -e
+
+key_expr="[a-zA-Z][_a-zA-Z0-9]*"
+
+file=.app/config
+
+while getopts "f:n:" opt
+do
+ case $opt in
+ f)
+ file=$OPTARG
+ ;;
+ n)
+ name=$OPTARG
+ ;;
+ \?)
+ echo "Invalid option: $OPTARG" >&2
+ exit 1
+ ;;
+ esac
+done
+
+if [ -z "$name" ]
+then
+ filter="s,^[ ]*\($key_expr\.$key_expr\)[ ]*=[ ]*\(.*\)$,\1=\2,p"
+else
+ filter="s,^\($name\)=\(.*\),\1=\2,p"
+fi
+
+if [[ $APPSH_DEFAULT_CONFIG == "" ]]
+then
+ APPSH_DEFAULT_CONFIG=$APPSH_HOME/lib/default-config
+fi
+
+# The awk script makes sure each key only appears once
+cat "$file" "$APPSH_DEFAULT_CONFIG" | \
+ sed -n -e "$filter" $extra | \
+ awk -F = ' (!($1 in a)){a[$1]; print }' | \
+ sort