autoload -U compinit promptinit
compinit
promptinit
prompt adam2
setopt nobeep

alias ls='ls --color=auto --group-directories-first'
alias grep='grep --color=auto'
alias tree='tree -dL 2'
alias read='cat $1 | less'

bindkey "\e[3~" delete-char

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'

if [ "$TERM" = "linux" ]; then
    echo -en "\e]P0050505"
    echo -en "\e]P8555753"
    echo -en "\e]P19c8093"
    echo -en "\e]P9ffadcc"
    echo -en "\e]P29ed3d7"
    echo -en "\e]PA67d797"
    echo -en "\e]P3ccc9a5"
    echo -en "\e]PBc4c497"
    echo -en "\e]P43f4f60"
    echo -en "\e]PC98a7b6"
    echo -en "\e]P5a488d9"
    echo -en "\e]PDb7a7bc"
    echo -en "\e]P68d9fa6"
    echo -en "\e]PEb8ddea"
    echo -en "\e]P7665c64"
    echo -en "\e]PF787a76"
    clear #for background artifacting
fi

# {{{ Functions
function extract () {
    if [[ -z "$1" ]]; then
        print -P "Usage: extract filename"
        print -P "Extract a given file based on the extension."
    elif [[ -f "$1" ]]; then
        case "$1" in
            *.tbz2 | *.tar.bz2) tar -xvjf "$1" ;;
            *.txz | *.tar.xz) tar -xvJf "$1" ;;
            *.tgz | *.tar.gz) tar -xvzf "$1" ;;
            *.tar | *.cbt) tar -xvf "$1" ;;
            *.zip | *.cbz) unzip "$1" ;;
            *.rar | *.cbr) unrar x "$1" ;;
            *.bz2) bunzip2 "$1" ;;
            *.xz) unxz "$1" ;;
            *.gz) gunzip "$1" ;;
            *.7z) 7z x "$1" ;;
            *.Z) uncompress "$1" ;;
            *) echo "Error: failed to extract '$1'" ;;
        esac
    else
        echo "Error: '$1' is not a valid file for extraction"
    fi
}
# }}}

preexec () {
	echo -ne "\ek${1%% *}\e\\"
}
