autoload -U parseopts
autoload -U zargs
autoload -U zcalc
autoload -U zed
autoload -U zmv

source ~/.zplug/init.zsh

zplug "robbyrussell/oh-my-zsh", use:"lib/*.zsh", nice:-1
zplug "plugins/brew",   from:oh-my-zsh
zplug "plugins/bundler",   from:oh-my-zsh
zplug "plugins/cp",   from:oh-my-zsh
zplug "plugins/dnf",   from:oh-my-zsh
zplug "plugins/docker",   from:oh-my-zsh
zplug "plugins/docker-compose",   from:oh-my-zsh
zplug "plugins/gem",   from:oh-my-zsh
zplug "plugins/git",   from:oh-my-zsh, nice:10
zplug "plugins/golang",   from:oh-my-zsh, nice:10
zplug "plugins/gpg-agent",   from:oh-my-zsh
zplug "plugins/history",   from:oh-my-zsh, nice:11
zplug "plugins/httpie",   from:oh-my-zsh, nice:10
zplug "plugins/mvn",   from:oh-my-zsh
zplug "lukechilds/zsh-nvm"
zplug "lukechilds/zsh-better-npm-completion", nice:10
zplug "plugins/node",   from:oh-my-zsh
zplug "plugins/npm",   from:oh-my-zsh
zplug "plugins/rake",   from:oh-my-zsh
zplug "plugins/rsync",   from:oh-my-zsh
zplug "plugins/ruby",   from:oh-my-zsh
zplug "plugins/shrink-path",   from:oh-my-zsh
zplug "plugins/ssh-agent",   from:oh-my-zsh
zplug "plugins/systemd",   from:oh-my-zsh
zplug "plugins/tmux",   from:oh-my-zsh, nice:10
zplug "plugins/kubectl",   from:oh-my-zsh, nice:10
zplug "plugins/vagrant",   from:oh-my-zsh
zplug "plugins/z",   from:oh-my-zsh
zplug "plugins/zsh_reload",   from:oh-my-zsh

zplug "k4rthik/git-cal", as:command
zplug "michaeldfallen/git-radar", as:command, use:git-radar

zplug "ndbroadbent/scm_breeze", hook-build:"$ZPLUG_HOME/repos/ndbroadbent/scm_breeze/install.sh"
zplug "djui/alias-tips"
zplug "supercrabtree/k"
zplug "chriskempson/base16-shell", use:"base16-3024.dark.sh"
zplug "zsh-users/zsh-completions", use:src
zplug "zsh-users/zsh-autosuggestions", nice:10
zplug "zsh-users/zsh-syntax-highlighting", nice:10
zplug "zsh-users/zsh-history-substring-search", nice:10
zplug "knu/zsh-manydots-magic"
zplug "mafredri/zsh-async"
zplug "so-fancy/diff-so-fancy", as:command
zplug "Masterminds/glide", as:command, from:gh-r, use:"*linux*amd64*", rename-to:glide
zplug "jimmidyson/07b69911f783e3afd8cd4c8f8358c8f6", from:gist, nice:10

zplug "openshift/source-to-image", \
  as:command, \
  from:gh-r, \
  use:"*linux*amd64*", \
  rename-to:s2i

if ! zplug check --verbose; then
    printf "Install? [y/N]: "
    if read -q; then
        echo; zplug install
    fi
fi

zplug load --verbose

# options
stty start undef  # disable C-s stopping receiving keyboard signals.
stty stop undef
setopt MENU_COMPLETE  # select first menu option automatically
setopt NO_NOMATCH  # stop zsh from catching ^ chars.
setopt PROMPT_SUBST  # prompt substitution
setopt AUTO_CONTINUE

export ENHANCD_FILTER=sk-tmux

# scm_breeze
[ -s "~/.scm_breeze/scm_breeze.sh" ] && source "~/.scm_breeze/scm_breeze.sh"

# theme
get_pwd() {
    git_root=$PWD
    while [[ $git_root != / && ! -e $git_root/.git ]]; do git_root=$git_root:h; done
    case $git_root in
    /)
      echo %{$fg_bold[yellow]%}$(shrink_path -f)%{$reset_color%}
      ;;
    $PWD)
      echo %{$fg_bold[yellow]%}$(shrink_path -f $git_root)%{$reset_color%}
      ;;
    *)
      echo %{$fg_bold[yellow]%}$(shrink_path -f $git_root)%{$reset_color%}%{$fg_bold[magenta]%}${$(shrink_path -f)#$(shrink_path -s -t $git_root)}%{$reset_color%}
      ;;
  esac
}
prompt_virtualenv() { [[ -n $VIRTUAL_ENV && -n $VIRTUAL_ENV_DISABLE_PROMPT ]] && echo "%{$fg_bold[white]%}($(basename $VIRTUAL_ENV)) "; }
autoload -Uz get_pwd
autoload -Uz prompt_virtualenv
autoload -Uz colors && colors
autoload -Uz promptinit && promptinit
PROMPT="%(?..%{$fg_bold[red]%}[%?]%{$reset_color%} )\$(get_pwd) \$(git-radar --zsh --fetch)\$(prompt_virtualenv)%{$fg_bold[magenta]%}λ%{$reset_color%} "

[ -s "/home/jdyson/.scm_breeze/scm_breeze.sh" ] && source "/home/jdyson/.scm_breeze/scm_breeze.sh"

alias vup='SSH_AUTH_SOCK="" vagrant up'

command -v hub >/dev/null 2>&1 && eval "$(hub alias -s)"
fpath=(/home/linuxbrew/.linuxbrew/share/zsh/site-functions $fpath)
compinit
alias vim=nvim

export OC_EDITOR=nvim
#export DOCKER_HOST=tcp://127.0.0.1:2376
#export DOCKER_TLS_VERIFY=1

export RUST_SRC_PATH=/home/jdyson/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src

alias gpg=gpg2
alias bfg='java -jar ~/apps/bfg/bfg.jar'

printcert() {
  echo | openssl s_client -connect $1 2>/dev/null | openssl x509 -text
}

bindkey -v
bindkey -M vicmd "?" history-incremental-pattern-search-forward
bindkey -M vicmd "/" history-incremental-pattern-search-backward
bindkey -M vicmd v edit-command-line
bindkey -M vicmd 'u' undo
bindkey -M vicmd '^r' redo
bindkey -M vicmd '~' vi-swap-case
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
bindkey '^[[Z' reverse-menu-complete
bindkey '^l' clear-screen
bindkey '^k' kill-line
bindkey '^u' backward-kill-line
bindkey '^r' history-incremental-search-backward
bindkey '^p' history-search-backward
bindkey '^n' insert-last-word
bindkey '^?' backward-delete-char

alias ocup='oc cluster up --host-data-dir=/var/lib/origin/openshift.local.etcd --routing-suffix=172.17.0.1.nip.io --use-existing-config --public-hostname=172.17.0.1'
alias ocdown='oc cluster down'
alias occlean='ocdown && sudo rm -rf /var/lib/origin/openshift.local.*'

func mkcd() {
  mkdir -p "$@"
  cd "${@: -1}"
}

export GITHUB_ACCESS_TOKEN=$(pass github/access)
export HOMEBREW_GITHUB_API_TOKEN=$(pass github/homebrew)

PATH="/home/jdyson/perl5/bin${PATH:+:${PATH}}"; export PATH;
PERL5LIB="/home/jdyson/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/home/jdyson/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/home/jdyson/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/home/jdyson/perl5"; export PERL_MM_OPT;

#export HOMEBREW_BUILD_FROM_SOURCE=1