#!/usr/bin/env bash
export starting="${BASH_SOURCE[0]}"; debug.sh starting

## SHELL ROOT
if test -n "${DARWIN}" && [[ "$( id -u )" == "0" ]] || [[ "${SUDO_UID-}" ]]; then
  if [[ -f /usr/local/bin/bash ]] && [[ "${SHELL}" != /usr/local/bin/bash ]]; then
    /usr/bin/sudo /usr/bin/chsh -s /usr/local/bin/bash > /dev/null 2>&1
    export SHELL=/usr/local/bin/bash
  fi
fi

## SHOPT
options="globstar direxpand checkwinsize histappend autocd cdable_vars dotglob hostcomplete no_empty_cmd_completion"
# shellcheck disable=SC2034
globstar="yes"
# shellcheck disable=SC2034
direxpand="yes"
# shellcheck disable=SC2034
checkwinsize="yes"
# shellcheck disable=SC2034
histappend="yes"
# shellcheck disable=SC2034
autocd="yes"
# shellcheck disable=SC2034
cdable_vars="yes"
# shellcheck disable=SC2034
dotglob="no"
# shellcheck disable=SC2034
hostcomplete="no"
# shellcheck disable=SC2034
no_empty_cmd_completion="yes"


for option in ${options}; do
  if [[ "${!option}" == "yes" ]]; then
    if [[ "${option}" =~ globstar|direxpand ]] && [[ "${BASH_VERSINFO[0]}" -gt 3 ]]; then
      shopt -s "${option}"
    fi
    if ! [[ "${option}" =~ globstar|direxpand ]]; then
      if test "${option}" != "autocd"; then
        shopt -s "${option}"
      elif test -n "${PS1}"; then
        shopt -s "${option}"
      fi
    fi
  else
    shopt -u "${option}"
  fi
done

## DIRCOLORS
if test "$( uname -s )" = "Linux" && test -f /usr/bin/dircolors; then
  eval "$( /usr/bin/dircolors -b )"
fi

## MACOS
paper.sh

if isuserdarwin.sh; then
  sudo rm -rf ~/Applications ~/Movies ~/Music ~/Pictures ~/Public ~/Sites >/dev/null 2>&1
  chmod go-rwx ~/.netrc >/dev/null 2>&1
  chmod -R go-rwx ~/.ssh >/dev/null 2>&1
  ! test -e /private/var/vm/sleepimage || sudo rm -rf /private/var/vm/sleepimage >/dev/null 2>&1
fi


## PS1
## xterm title set to host@user:dir lo hace con esto: \[\e]0;\h@\u: \w\a\]
SSH_THE_SAME="yes"
if [[ "$( id -u )" == "0" ]] || [[ "${SUDO_UID-}" ]]; then
    PS1="\[\e]0;\h@\u: \w\a\]${ROJO}\h${INVERSO} ${AZUL}\w${INVERSO} ${ROJO}#${INVERSO} "
else
  if [[ "$(uname -s)" == "Darwin" ]] || [[ "${SSH_THE_SAME-}" ]]; then
    PS1="\[\e]0;\h@\u: \w\a\]${VERDE}\h${INVERSO} ${AZUL}\w${INVERSO} ${VERDE}\$${INVERSO} "
  else
    PS1="\[\e]0;\h@\u: \w\a\]${VERDE}\h${INVERSO} ${AZULCLARO}\u${INVERSO} ${AZUL}\w${INVERSO} ${VERDE}\$${INVERSO} "
  fi
fi
export PS1

unset starting option
