#!/bin/bash
SOURCE="$0"
source /usr/lib/elive-tools/functions
EL_REPORTS="1"

main(){
    # pre {{{
    local i arg

    # install dependencies, especially if we don't have other compatible choices
    if ! el_dependencies_check "rxvt-unicode" ; then
        el_dependencies_install "rxvt-unicode"
    fi

    # }}}

    for i in "$@"
    do
        case "$i" in
            "-hold")
                if [[ -x "$(which rxvt-unicode)" ]] ; then
                    arg+=("-hold")
                #elif [[ -x "$(which terminology)" ]] ; then
                #    arg+=("-H")
                fi
                ;;

            "-e"|"--")
                is_ignore_more_args=1
                shift
                ;;
            "-"*)
                # ignore all options
                if ((is_ignore_more_args)) ; then
                    commands+=("$i")
                else
                    shift
                fi
                ;;
            *)
                # add an argument (dest dir) to the array
                if ! echo "$@" | grep -qsE "\s+\-\-\s+" ; then
                    commands+=("$i")
                fi
                shift
                ;;
        esac
    done

    if [[ -x "$(which rxvt-unicode)" ]] ; then
        el_debug "Running: rxvt-unicode \"${arg[@]}\" -e \"${commands[@]}\""
        rxvt-unicode "${arg[@]}" -e "${commands[@]}"
    else
        el_notify normal gtk-warning "Unable to run terminal" "There's not compatible terminals found to run, please install rxvt-unicode"
        # warning: terminlogy is not compatible
        #if [[ -x "$(which terminology)" ]] ; then
        #terminology "${arg[@]}" -e "${commands[@]}"
        #fi
    fi

}

#
#  MAIN
#
main "$@"

# vim: set foldmethod=marker :
