#!/bin/sh

APP_PATH=${APP_PATH:-${HOME:-.}/share/apps:/usr/local/share/apps:/usr/local/apps:/usr/share/apps}

find_app()
{
    echo $APP_PATH | tr ":" "\n" | \
    while read dir; do
        if [ -d "$dir" ]; then
            if [ -x "$dir"/"$1"/AppRun ]; then
                echo $dir/$1
                return
            fi
        fi
    done
}

case "$1" in
    --xmms) shift; exec xmms "$@" ;;
    --mixer) shift; exec gmix "$@" ;;
    --cdplay) shift; `find_app CD-ROM`/AppRun --player "$@" ;;
    --*) exit 1 ;;
esac

if [ $# -gt 0 ]; then
    exec xmms -e "$@"
else
    exec xmms
fi
