#!/bin/dash
# Launch a default program
# Copyright (C) James Budiono, 2014
# 
# Usage: this program should be linked to defaultpaint, defaultbrowser, etc
#

### configuration ###
SYSTEM_DEFAULTS=/etc/defaultprograms
LOCAL_DEFAULTS=$FATDOG_STATE_DIR/defaultprograms
[ -e $SYSTEM_DEFAULTS ] && . $SYSTEM_DEFAULTS # load system's first
[ -e $LOCAL_DEFAULTS ] && . $LOCAL_DEFAULTS   # override with local settings

### main ###
# find the program name and the registry name
progname=${0##*/}
appname=${progname#default} # make sure not clash with real environment names
registryname=DEF_$(echo "$appname" | tr 'a-z' 'A-Z')

# and launch the program if it is not empty
eval cmd=\$$registryname
[ -e $FATDOG_STATE_DIR/language ] && read LANG < $FATDOG_STATE_DIR/language # L18L
[ "$cmd" ] && exec $cmd "$@"
