#~/.bashrc: executed by bash(1) for non-login shells.

export PATH=~/DotFiles/bin:$PATH

export DIFFDIR=~/diffs
export SCRIPTITY=/mnt/ssd

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

# colored man pages!
  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'

# all the cool features
  bind "set completion-ignore-case on"
  bind "set completion-map-case on"
  bind "set show-all-if-ambiguous on"
  bind 'TAB:menu-complete'
  bind 'set show-mode-in-prompt on'
  bind -m vi-insert "\C-l":clear-screen

  shopt -s dirspell 2> /dev/null
  shopt -s checkwinsize

# better completion?
  complete -cf man

# basics
  export EDITOR=vim
  export PATH=$PATH:/sbin:/usr/local/sbin:/usr/sbin
  export PROMPT_DIRTRIM=5
  bind '"\e[A": history-search-backward'
  bind '"\e[B": history-search-forward'

# functions
_prompt() {
  local tmp dir_abbr ps1

  tmp=$(sed -r 's/(\/.)[^/]*/\1/g' <<< "${PWD/$HOME/\~}")
  dir_abbr="${tmp:0:$(( ${#tmp} - 1 ))}"
  ps1="$(basename "${PWD}")"

  if [[ ${#ps1} -gt 25 ]]; then
    ps1="${ps1:0:7}...${ps1: -7}"
  fi

  echo -n "${dir_abbr}${ps1}"
}

c() { cd "$@" && ls --color;}

parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

# History
  HISTCONTROL=ignoreboth
  shopt -s histappend
  HISTSIZE=5000
  HISTFILESIZE=10000
  export HISTTIMEFORMAT="%h/%d - %H:%M:%S "

# 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

# colors + prompt
  case "$TERM" in
    xterm-color) color_prompt=yes;;
  esac
  force_color_prompt=yes

  if [[ -n "$force_color_prompt" ]]; then
    if [[ -x /usr/bin/tput ]] && tput setaf 1 >&/dev/null; then
      color_prompt=yes
    else
      color_prompt=
    fi
  fi

  if [[ "$color_prompt" == yes ]]; then
    host=$(hostname | sed -e 's/localhost/home/')
    host=$(sed -e 's/wkstn-avoecks/work/' <<< "$host")
    PS1='\[\033[01;32m\]\u@${host}\[\033[00m\] \[\033[01;36m\]$(_prompt)\[\033[00m\]$(parse_git_branch)> '

  else
    echo
  fi
  unset color_prompt force_color_prompt

# enable color support of ls and also add handy aliases
  if [[ -x /usr/bin/dircolors ]]; then

    if test -r ~/.dircolors; then
      eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    fi
  fi

[[ -f ~/.fzf.bash ]] && source ~/.fzf.bash
[[ -f ~/DotFiles/lib/common.sh ]] && source ~/DotFiles/lib/common.sh

# minio being messy
complete -C /home/leaf/.local/bin/mc mc
complete -C /usr/home/leaf/.local/bin/mc mc

[[ -f "$HOME"/.cargo/env ]] && source "$HOME"/.cargo/env
