#!/bin/sh
#
# Usage: $0 item [default]
#
# Reads the given config item from the config files in
# ${UMLCONFS} (default: ./uml.conf:~/.uml.conf). First match is used.
# If the item is missing, returns the given default value.
# If no default is given returns "" and an exit code of 1 (instead of 0)

[ -z "${UMLCONFS}" ] && UMLCONFS=uml.conf:~/.uml.conf

ITEM=`grep "^$1=" ${UMLCONFS/:/ } 2>/dev/null | head -1`
if [ -z "${ITEM}" ]; then
  if [ $# -eq 2 ]; then
    echo "$2"
    exit 0
  fi
  echo 1>&2 "Configuration item $1 not found"
  exit 1
fi
echo "$ITEM" | sed -e "s/^[^=]*=//"
