#!/bin/bash

# Do Not Modify This File, It's Intended To Be Updated From Time to Time
# INSTEAD: add additional functionality though the .bash_customize file.

autocomplete() {

  if command -v pib_cli >/dev/null 2>&1; then
    eval "$(_PIB_CLI_COMPLETE=bash_source pib_cli)"
    eval "$(_DEV_COMPLETE=bash_source dev)"
  fi

  # shellcheck source=/dev/null
  [[ -f /usr/share/bash-completion/completions/git ]] && source /usr/share/bash-completion/completions/git

}


shell_customize() {

  # Terminal Colors
  if [[ -x /usr/bin/dircolors ]]; then
      # shellcheck disable=SC2015
      test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
      alias ls='ls --color=auto'
      alias grep='grep --color=auto'
      alias fgrep='fgrep --color=auto'
      alias egrep='egrep --color=auto'
  fi

  set -e
    # shellcheck source=/dev/null
    [[ -f /home/user/.bash_customize ]] && source /home/user/.bash_customize
    # shellcheck source=/dev/null
    [[ -f /home/user/.bash_git ]] && source /home/user/.bash_git
  set +e

  HOME_BINARY_PATH="/home/user/.local/bin/"
  PROMPT_COMMAND="git_status; $PROMPT_COMMAND"

  # shellcheck disable=SC2154
  PS1='${git_branch}${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

  if [[ "${PATH}" != *"${HOME_BINARY_PATH}"* ]]; then
    # Add the local bin to path, if it's not present from Docker Environment
    export PATH="/home/user/.local/bin/:${PATH}"
  fi

}

shellcheck_scripts() {
  find scripts -type f -exec shellcheck -x "{}" \;
}

# shellcheck source=/dev/null
source "$(poetry env info -p)/bin/activate"

shell_customize
autocomplete
