#
# Editor
#
if -exe emacs; then
    export EDITOR='emacs -nw'
fi
if -exe vim; then
    export EDITOR='vim'
fi

alias e=$EDITOR

if [ -n "$EDITOR" -a -n "$SUDO_USER" -a "$UID" = 0 -a "$EDITOR[1,5]" = 'emacs' ]; then
    e="$EDITOR -u $SUDO_USER"
fi

#
# Pager
#
if -exe vim; then
    export PAGER=~/.vim/bin/vimpager
    alias less="$PAGER"
    alias more="$PAGER"
elif -exe most; then
    export PAGER=most
    alias less="$PAGER"
    alias more="$PAGER"
elif -exe less; then
    export PAGER=less
elif -exe more; then
    export PAGER=more
fi

#
# Common aliases
#
alias rm='rm -i'
alias mv='mv -i'
alias cp='cp -i'

alias vlock='clear;vlock'
alias q='clear;exit'

alias grep="grep --color=tty"
alias mgrep="grep --color=tty -rnisH"

alias rsu="sudo -E zsh"
alias reload="exec zsh"

alias tmux="tmux -2"

#
# Log viewers aliases
#
if -exe ccze; then
    alias slog="tail -n 300 -f /var/log/syslog | ccze"
    alias mlog="tail -n 300 -f /var/log/mail.log | ccze"
    alias xlog="tail -n 300 -f /var/log/Xorg.0.log | ccze"
else
    alias slog="tail -n 300 -f /var/log/syslog"
    alias mlog="tail -n 300 -f /var/log/mail.log"
    alias xlog="tail -n 300 -f /var/log/Xorg.0.log"
fi
# using colortail if available (freebsd)
if -exe colortail; then
    alias slog="colortail -n 60 -k /usr/local/share/examples/colortail/conf.messages -f /var/log/syslog"
fi

#
# System tools aliases
#
alias df='df -h'
if -exe pydf; then
    alias df="pydf -h"
fi

#
# Devel tools aliases
#
if -exe colordiff; then
    diff='colordiff'
    if -exe tput; then
        alias cdiff='colordiff -yW$(tput cols)'
    fi
fi

if -exe colormake; then
    alias make="colormake"
fi

#
# Git stuff
#
if [ -z "$GIT_PAGER" ]; then
    for p in less more cat; do
        if -exe "$p"; then
            alias git="PAGER=$p git"
            break
        fi
    done
fi

#
# Mssh stuff
#
if [ -f ~/.ssh/config ]; then
    hosts=($(grep '^Host [^*]' ~/.ssh/config | sed 's/Host //'))
    compctl -k hosts mssh
fi

