#!/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>"

### new.method

index.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 ...nothing yet
  
  Examples
    $this v
    $this init
  "
}

index.create.all() {
  if [ -d "./all" ]; then
    rm -Rf ./all
  fi
  mkdir ./all
  find . -type l -print0 | xargs -0 -n 1 index list.linkedDirectory | xargs -0 -n 1  index link.directory all

  tree -L 2 ./
}



index.list.linkedDirectory() {
  local target=$(readlink "$1")

  find "$target." -maxdepth 1 -mindepth 1 -print0

}

index.link.directory() {
  this.absolutePath "$1"
  local target="$RESULT"
  cd "$target"
  #echo "$target"
  shift

  
  local link="$target$1"
  link="${link/$target/}"
  echo "$link"
  ln -s "$link"
  shift

  RETURN="$1"
}


index.list.linkedDirectory.completion() {
    compgen -o dirnames "$1" | grep "^$1" 
}

index.start()
{
  #echo "sourcing init"
  source this

  # if [ -z "$1" ]; then
  #   status.discover "$@"
  #   return 0
  # fi

  this.start "$@"
}

index.start "$@"

