#!/usr/bin/sh

#*********************************************************************************************************
#*   __     __               __     ______                __   __                      _______ _______   *
#*  |  |--.|  |.---.-..----.|  |--.|   __ \.---.-..-----.|  |_|  |--..-----..----.    |       |     __|  *
#*  |  _  ||  ||  _  ||  __||    < |    __/|  _  ||     ||   _|     ||  -__||   _|    |   -   |__     |  *
#*  |_____||__||___._||____||__|__||___|   |___._||__|__||____|__|__||_____||__|      |_______|_______|  *
#* http://www.blackpantheros.eu | http://www.blackpanther.hu - kbarcza[]blackpanther.hu * Charles Barcza *
#*************************************************************************************(c)2002-2022********
. /etc/blackPanther-default-apps.conf

[ ! -n "$TERM_FORMAT" ] && TERM_FORMAT="-fs 12 +sb -bg black -fg white -geometry 80x30"

DEF_NAME="$(echo $@ | cut -d' ' -f1-2 | grep name)"

if [ -n "$DEF_NAME" ];then
	DEF_PAR="$(echo $@ | sed -e "s|$DEF_NAME||" -e 's|.*-hold\ ||'  -e 's|\ .*hold||')"
    else
	DEF_PAR="$(echo $@ | sed 's|.*-hold||')"
fi

if [ -n "$DEF_NAME" ]&&[ -n "$(echo "$DEF_PAR" | grep '\-e')" ];then
    DEF_PAR=$(echo "$DEF_PAR" | sed 's|-e ||')
    echo "Xterm Command fix1 : xterm -hold $DEF_NAME -e $DEF_PAR"
    xterm $TERM_FORMAT -hold $DEF_NAME -e "$DEF_PAR"
elif [ ! -n "$DEF_NAME" ]&&[ -n "$(echo "$DEF_PAR" | grep '\-e')" ];then
    DEF_PAR=$(echo "$DEF_PAR" | sed 's|-e ||')
    echo "Xterm Command fix2 : xterm -e $DEF_PAR"
    xterm $TERM_FORMAT -hold -e "$DEF_PAR"
#elif [ -n "$DEF_NAME" ]&&[ ! -n "$(echo "$DEF_PAR" | grep '\-e')" ];then
#    DEF_PAR=$(echo "$DEF_PAR" | sed 's|-e ||')
#    echo "Xterm Command fix3 : xterm -e $DEF_PAR"
#    xterm $TERM_FORMAT -hold -e "$DEF_PAR"
elif [ -n "$(echo "$@" | grep '-')" ]&&[ ! -n "$DEF_NAME" ];then
    echo "Xterm Command fix4 : xterm -e $DEF_NAME$DEF_PAR"
    xterm $TERM_FORMAT -hold $*
else
    echo "Xterm Command fix5 : xterm $@"
    xterm $TERM_FORMAT -hold $@
fi
