# skip customization for non-interactive shells
if [[ ! -o interactive ]]; then
  return
fi

# Timeout, in hundredths of seconds, when reading bound multi-character
# sequences (default is 0.4 sec.)
KEYTIMEOUT=1

# List of non-alphanumeric characters considered part of a word
export WORDCHARS='*?_-.[]~=&;!#$%^(){}<>'

# Do not create a history file for less
export LESSHISTFILE=/dev/null

# Disable features like shell or pipe commands and more in less
export LESSSECURE=1

# completion system
autoload -U compinit; compinit

# retrieve information from version control systems
autoload -Uz vcs_info

# Case-insensitive, partial-word and then substring completion
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'

# Offers menu when > selected elements appear
zstyle ':completion:*' menu select

# Specify enabled vcs backends
zstyle ':vcs_info:*' enable git

# Specify how it should be formatted
zstyle ':vcs_info:*' formats '%b'

# Disable beeping on errors
unsetopt BEEP

# Define size for HISTSIZE and SAVEHIST also define path for HISTFILE
HISTSIZE=8192
SAVEHIST=8192

# Make cd push the old directory onto the directory stack
setopt AUTO_PUSHD

# Exchanges the meanings of "+" and "-" when used with a number to specify a directory in the stack
setopt PUSHD_MINUS

# Do not print the directory stack after pushd or popd
setopt PUSHD_SILENT

# Do not push copies of the directory onto the directory stack
setopt PUSHD_IGNORE_DUPS

# The maximum size of the directory stack (no limit by default)
DIRSTACKSIZE=8

# Remove command lines from the history list when the first character on the line is a space
setopt HIST_IGNORE_SPACE

# When writing out the history file, older commands that duplicate newer ones are omitted
setopt HIST_SAVE_NO_DUPS

# Enable vcs_info
setopt PROMPT_SUBST

# Comfortable aliases
alias ..='cd ..'
alias cp='cp -v'
alias l='ls -F -h'
alias la='ls -F -h -A'
alias mv='mv -v'
alias view='vim -R'

# Comfortable git aliases
alias g='git'
alias gc='g commit'
alias gd='g diff'
alias glog='g log --graph --oneline'
alias gst='g status --short --branch'

# Suppresses line numbers in less
alias less='less --line-numbers'

# Create temporary directory and cd to it
alias cdt='builtin cd "$(mktemp -d)"'

# Defines the prompt
precmd() {
  vcs_info

  # check if vcs_info_msg_0_ is empty to avoid an anoying space in the prompt
  if [[ -z ${vcs_info_msg_0_} ]]; then
    PS1='%B%F{green}%(3~|…/%2~|%~)%f %%%b '
  else
    PS1='%B%F{green}%(3~|…/%2~|%~)%f %F{cyan}${vcs_info_msg_0_}%f %%%b '
  fi
}

# include reading files from directory
for f in "${HOME}"/.zsh/*; do
  source "$f"
done

unset f