#!/bin/bash

#########################
# Variáveis de Ambiente #
#########################

# Set the default editor
export EDITOR=nano
export VISUAL=nano
export HISTCONTROL=erasedups:ignoredups:ignorespace
HISTSIZE=10000
HISTFILESIZE=500
shopt -s histappend
PROMPT_COMMAND='history -a'

# Color for manpages in less makes manpages a little easier to read
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'

# For chatgpt and other cositas mas!
export PATH="$PATH:$HOME/.local/bin"

################
# Condicionais #
################

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# Check the window size after each command and, if necessary, update the values of LINES and COLUMNS
shopt -s checkwinsize

# Allow ctrl-S for history navigation (with ctrl-R)
stty -ixon

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# ==============================================================================
# Colors for Terminal
# ==============================================================================

NONE="\[\033[0m\]" # Eliminar as Cores (deixar padrão)

## Cores de Fonte
W="\[\033[0;37m\]" # White (Branco)

R="\[\033[0;31m\]" # Red (Vermelho)
G="\[\033[0;32m\]" # Green (Verde)
B="\[\033[0;34m\]" # Blue (Azul)

C="\[\033[0;36m\]" # Cyan (Ciano - Azul Claro)
M="\[\033[0;35m\]" # Magenta (Vermelho Claro)
Y="\[\033[0;33m\]" # Yellow (Amarelo)
K="\[\033[0;30m\]" # Black (Preto)

## Efeito Negrito (bold) e cores
BW="\[\033[1;37m\]" # Bold+White (Negrito+Branco)
BR="\[\033[1;31m\]" # Bold+Red (Negrito+Vermelho)
BG="\[\033[1;32m\]" # Bold+Green (Negrito+Verde)
BB="\[\033[1;34m\]" # Bold+Blue (Negrito+Azul)
BC="\[\033[1;36m\]" # Bold+Cyan (Negrito+Ciano - Azul Claro)
BM="\[\033[1;35m\]" # Bold+Magenta (Negrito+Vermelho Claro)
BY="\[\033[1;33m\]" # Bold+Yellow (Negrito+Amarelo)
BK="\[\033[1;30m\]" # Bold+Black (Negrito+Preto)

## Cores de fundo (backgroud)
BGW="\[\033[47m\]" # White (Branco)
BGR="\[\033[41m\]" # Red (Vermelho)
BGG="\[\033[42m\]" # Green (Verde)
BGB="\[\033[44m\]" # Blue (Azul)
BGC="\[\033[46m\]" # Cyan (Ciano - Azul Claro)
BGM="\[\033[45m\]" # Magenta (Vermelho Claro)
BGY="\[\033[43m\]" # Yellow (Amarelo)
BGK="\[\033[40m\]" # Black (Preto)

# Uncomment to turn on!
force_color_prompt=yes

# ==============================================================================

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

# .bashrc
_docker() {
    if [[ "$1" == "exec" ]]; then
        /bin/sh
        return 0
    fi
    command docker "$@"
}
alias docker='_docker'

if [ "$color_prompt" = yes ]; then

  # Color based if is root or not. Same for all users!

  if [ `whoami` != 'root' ]; then
    PS1="$BK┌─$BK[$BB\u$BK]$BR@$BK[$BB\h$BK]$BR:$BK[$BC\w$BK] $BK \n$BK└──╼ $BR$ $NONE"
  else
    PS1="$BK┌─$BK[$BR\u$BK]$BR@$BK[$BR\h$BK]$BR:$BK[$BY\w$BK] $BK \n$BK└──╼ $BR$ $NONE"
  fi

  # BKP OLD ONES
  #PS1="$BG┌─[$BC\u$BG]$BR@$BG[$BB\h$BG]:$BG[$BY\w$BG] \n└──╼ $ $NONE"
  #PS1="$BK┌─$BK[$BR\u$BK]$BR@$BK[$BR\h$BK]$BR:$BK[$BR\w$BK] $BK \n└──╼ $BR$ $NONE"
  #PS1="$BR┌─[$BG\u$BR]$BY@$BR[$BW${HOSTNAME%%.*}$BR]$B:\w\n$BR└──>$BG Ω $NONE"
  #PS1="\e[01;31m┌─[\e[01;35m\u\e[01;31m]──[\e[00;37m${HOSTNAME%%.*}\e[01;32m]:\w$\e[01;31m\n\e[01;31m└──\e[01;36m>>\e[00m"
  #PS1="┌─[\[\e[34m\]\u\[\e[0m\]][\[\e[34m\]\h\[\e[0m\]][\[\e[34m\]\w\[\e[0m\]]\n└─╼ "
  #PS1="$G┌─[$BR\u$G]$BY@$G[$BW${HOSTNAME%%.*}$G]$B:\w\n$G└──>$BR \\$ $NONE"

  # Default
  #PS1='[\u@\h \W]\$ '

  else
  	# Default terminal colors/scheme.
  	PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    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

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi
