#!/usr/bin/env bash
#clear
#export PS4='\e[90m+${LINENO} in ${#BASH_SOURCE[@]}>${FUNCNAME[0]}:${BASH_SOURCE[@]##*/} \e[0m'
#set -x

#echo "starting: $0 <LOG_LEVEL=$1>"



status.discover()
{

  if [ -z "$USER" ]; then
    USER=$(whoami)
    export USER
  fi

  if [ -z "$USERHOME" ]; then
    this.absolutePath ~/.bashrc >/dev/null
    # echo "$RESULT"
    USERHOME=$RESULT
    export USERHOME
  fi

  if [ -z "$OOSH_STATUS" ]; then
    if [ -f "./oosh" ]; then
      OOSH_STATUS="1: not in PATH, but installable via ./oosh"
    else
      OOSH_STATUS="2: not installed, not in PATH"
      export OOSH_STATUS
    fi
  fi
  

  #clear
  echo "status.discover:
        current shell : $SHELL  -> $(command -v bash)
               version: ${BASH_VERSION}"
  #echo "$(bash --version)"
  echo "              
                level: $SHLVL

                script: $0
                args  : $*
                dir   : $(pwd)

              hostname: $HOSTNAME
                type  : $HOSTTYPE
                OS    : $OSTYPE
       package manager: $OOSH_PM

          current user: $USER
                  home: $USERHOME

           OOSH STATUS: $OOSH_STATUS
           OOSH PATH  : $OOSH_DIR

           CONFIG     : $CONFIG
           LOG_LEVEL  : $LOG_LEVEL

          current PATH: $PATH"
  #loop.list PATH print '---------------------: '
  status.path '----------------------:'
          
}

status.path()
{
  loop list PATH print "$1"
}

status.scope()
{
  this.scope
}

status.scope.full()
{
  this.scope.full
}

status.usage()
{
  local this=${0##*/}
  echo "You started 
$0

  Usage:
  $this: command   description and Parameter

      usage     prints this dialog while it will print the status when there are no parameters          
      v         print version information
      init      initializes a new user config  
  
  Examples
    $this v
    $this init
  "
}

status.start()
{
  #echo "sourcing init"
  #LOG_LEVEL=6
  source this

  if [ -z "$1" ]; then

    status.discover "$@"
    return 0
  fi

  this.start "$@"
}

status.start "$@"

