#! /bin/sh
#+++
#  title:	setpref
#  abstract:	set user default for NEXTSTEP and/or OPENSTEP.
#  author:	Tom Hageman <tom@basil.icce.rug.nl>
#  created:	November 1997
#  modified:
#  copyleft:
#
#	Copyright (C) 1997 Tom R. Hageman, but otherwise perfect freeware.
#
#  description:
#	Usage: setpref [-r] [domain | -g] [-N <NEXTSTEP-key>] [-O <OPENSTEP-key>] value.
#
#---

PATH=/usr/ucb:/bin:/usr/bin export PATH

err=/dev/null
#err=/dev/console

Usage() {
   echo "Usage: `basename $0` [-r] [domain | -g] [-N NEXTSTEP-key] [-O OPENSTEP-key] value" >&2
   exit 2
}

case "$1" in
-r) action=dremove; shift ;;
*)  action=dwrite ;;
esac

domain="$1"

case "$2" in
-N) nskey="$3" ;;
-O) oskey="$3" ;;
*)  Usage
esac

case $# in
3|4)
    value="$4" ;;
5|6)
    case "$4" in
    -N) nskey="$5" ;;
    -O) oskey="$5" ;;
    *)  Usage
    esac
    value="$6" ;;  
*)
    Usage
esac

case "$nskey" in
"") ;;
*)
    $action "$domain" "$nskey" "$value" ;;
esac 2>$err

case "$oskey" in
"") ;;
*)
    case "$domain" in
    -g)  domain=NSGlobalDomain
    esac
    case $action in
    dwrite)  defaults write "$domain" "$oskey" "$value" ;;
    dremove) defaults delete "$domain" "$oskey" ;;
    esac
esac 2>$err
