#complist
# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
export HISTCONTROL=ignoredups
_JAVA_AWT_WM_NONREPARENTING=1; export _JAVA_AWT_WM_NONREPARENTING

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(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


PERL5LIB=$HOME/local/lib64/perl5/site_perl/5.8.8/
autoload -U compinit
compinit
setopt extended_glob
bindkey -e
#ZLS_COLORS=$LS_COLORS


#export DISTCC_HOSTS='hyades01 hyades02 hyades03 hyades04'
#if [[ "$GOROOT" == "" ]]; then
  #export GOROOT=$HOME/local/go
  #export GOARCH=amd64
  #export GOOS=linux
#case `uname` in
#Darwin)
	#export GOOS=darwin
	#;;
#FreeBSD)
	#export GOOS=freebsd
	#;;
#esac
#fi


setopt prompt_subst


###
# See if we can use colors.

autoload colors zsh/terminfo
if [[ "$terminfo[colors]" -ge 8 ]]; then
  colors
fi
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
  eval PR_LIGHT_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
  eval PR_$color='%{$fg[${(L)color}]%}'
  (( count = $count + 1 ))
done
PR_NO_COLOUR="%{$terminfo[sgr0]%}"

case `uname` in
  Darwin)
    PR_HOST_COLOR=$PR_CYAN
    ;;
  Linux)
    PR_HOST_COLOR=$PR_GREEN
    ;;
  FreeBSD)
    PR_HOST_COLOR=$PR_RED
    ;;
  *)
    PR_HOST_COLOR=$PR_YELLOW
    ;;
esac

#PR_HOST_COLOR=$PR_NO_COLOUR
#if [ -x "$(command -v $MD5_COMMAND)" ]; then
  #str=`echo -n "${HOST} ${HOSTNAME}" | $MD5_COMMAND $MD5_COMMAND_OPTS`
  #last="${str: -1}"
  #echo
  #case $last in
    #"1"|"6"|"b"|"0")
      #PR_HOST_COLOR=$PR_GREEN
      #;;
    #"2"|"7"|"c")
      #PR_HOST_COLOR=$PR_YELLOW
      #;;
    #"3"|"8"|"d")
      #PR_HOST_COLOR=$PR_BLUE
      #;;
    #"4"|"9"|"e")
      #PR_HOST_COLOR=$PR_MAGENTA
      #;;
    #"5"|"a"|"f")
      #PR_HOST_COLOR=$PR_CYAN
      #;;
    #"*")
      #;;
  #esac
#fi


PROMPT='$PR_STITLE$PR_LIGHT_BLUE(%(!.$PR_RED.$PR_LIGHT_YELLOW)%D{%H:%M}|%!$PR_BLUE%)[%(!.$PR_RED.$PR_HOST_COLOR)%n@%m$PR_LIGHT_CYAN %~$PR_BLUE]$PR_NO_COLOUR
%(!.#.$) '
	#source .zshprompt

#source ~/.zsh_profile
source ~/.zprofile
if [ -f ~/.bash_aliases ]; then
    source ~/.bash_aliases
fi

if [ -f /usr/local/bin/virtualenvwrapper_lazy.sh ]; then
    source /usr/local/bin/virtualenvwrapper_lazy.sh
elif [ -f /usr/bin/virtualenvwrapper_lazy.sh ]; then
    source /usr/bin/virtualenvwrapper_lazy.sh
fi

fasd_cache="$HOME/.fasd-init-zsh"
if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then
    fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcompinstall >| "$fasd_cache"
  fi

[ -f ~/.fzf.bash ] && source ~/.fzf.bash


[ -f  /usr/share/fzf/key-bindings.zsh ] && source /usr/share/fzf/key-bindings.zsh
[ -f  /usr/share/fzf/shell/key-bindings.zsh ] && source /usr/share/fzf/shell/key-bindings.zsh
[ -f  /usr/share/fzf/completion.zsh ] && source /usr/share/fzf/completion.zsh

export FZF_DEFAULT_COMMAND='rg --files --hidden --follow -g "!{.git,node_modules}/*" 2> /dev/null'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
#bind -x '"\C-p": vim $(fzf);'

source "$fasd_cache"
unset fasd_cache


source ~/.zshenv

##############################################################
## Stuff from http://zshwiki.org/home/examples/compquickstart #
###############################################################
zmodload zsh/complist
autoload -U compinit && compinit
zstyle ':completion:::::' completer _complete _approximate
zstyle -e ':completion:*:approximate:*' max-errors 'reply=( $(( ($#PREFIX + $#SUFFIX) / 3 )) )'
zstyle ':completion:*:descriptions' format "- %d -"
zstyle ':completion:*:corrections' format "- %d - (errors %e})"
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
zstyle ':completion:*' group-name ''
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*' menu select
zstyle ':completion:*' verbose yes
## case-insensitive (uppercase from lowercase) completion
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
#zstyle ':completion:*' special-dirs ..

if [ -n "`which fortune`" ]; then
    fortune
fi

# The next line updates PATH for the Google Cloud SDK.
if [ -f '/home/barak/local/google-cloud-sdk/path.zsh.inc' ]; then source '/home/barak/local/google-cloud-sdk/path.zsh.inc'; fi

# The next line enables shell command completion for gcloud.
if [ -f '/home/barak/local/google-cloud-sdk/completion.zsh.inc' ]; then source '/home/barak/local/google-cloud-sdk/completion.zsh.inc'; fi

if [ -f '/usr/local/lib/bazel/bin/_bazel' ]; then source '/usr/local/lib/bazel/bin/_bazel'; fi

# This enables autocomplete for kubectl
if [ $commands[kubectl] ]; then
  source <(kubectl completion zsh)
fi

export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"

if [ -f "$HOME/.zsh_work_rc" ]; then source $HOME/.zsh_work_rc; fi
