#!/bin/bash
#
# vim:tabstop=3:expandtab:shiftwidth=3
#

#
# Load values in keys from the output format of:
#
#   gsettings list-recursively org.gnome.GWeather
#

_help_show_args="[gsettings-list-recursively-file] [file2]"
if [ -f $(dirname $0)/_option_processor ]
then
   . $(dirname $0)/_option_processor
fi

if [ $# -eq 0 ]
then
   set -- /dev/stdin
fi

InputLine='^\s*\([^[:space:]]\+\)\s\+\([^[:space:]]\+\)\s\+\([^[:space:]].*\)\s*$'

while [ $# -ne 0 ]
do
   if [ ! -e $1 ]
   then
      echo "## File $1 not found"
   else
      echo "## loading from file $1" | sed 's,file /dev/\(.*\),(\1),'
      sed 's/#.*//g' $1 | grep -v '^[[:space:]]*$' | \
      while read
      do
         if grep -q "$InputLine" <<< "$REPLY"
         then
            sed 's|'"$InputLine"'|# gsettings set \1 \2 \3|' <<< "$REPLY"
            eval $(sed 's|'"$InputLine"'|gsettings set \1 \2 "\3"|' <<< "$REPLY")
         fi
      done
   fi
   shift
done

