alias y="noglob youtube-fast"
unset LESS
unset LESSOPEN
alias u="unrar x"
alias mplayersd="mplayer -lavdopts threads=1"
alias mplayersdsubs="DISPLAY=:0.2 mplayer -fs -lavdopts threads=1 -vf expand=:::::16/9:"
alias mplayersubs="DISPLAY=:0.2 mplayer -fs -vf expand=:::::16/9:"
alias less=most
alias nano="nano -w -E -T 4"
export EDITOR='emacs -nw'
source $HOME/.env
#stty erase \^h
stty erase '^?'
WORDCHARS=${WORDCHARS:s-/--}
eval `dircolors -b`
reniceall='renice 15 `pidof namn`'
alias week='date +%V'
alias e="cd ~/dev/engine"
alias q="qdepends -Q"
alias cp="cp"
alias qiv="qiv -i"
alias mv="mv"
alias es="sudo emerge --nospinner -s"
alias ep="sudo emerge --nospinner -pv"
alias em="sudo emerge --nospinner"
alias ev="sudo emerge --nospinner -va"
alias ef="sudo emerge --nospinner -f"
alias eix="noglob eix"
alias s="ssh -p 2233 bub"
alias m="ssh -p 2233 mini"
export REPORTTIME=20
export PAGER=most
#export PSPDEV=/usr/local/pspdev
#export PSPSDK=$PSPDEV/psp/sdk
#:$PSPDEV/bin
#export MANPATH=$MANPATH:$PSPDEV/man
#:/x/gc/lib
#/gba/gcc-arm/bin:/gba/gcc-arm/lib
#PS1=$'%{\e[0;32m%}%m%40<...<%{\e[1;31m%}%~%<<%{\e[1;34m%}'$'%# %(?.%{\e[0m%}.%{\e[1;31;42m%}%?%{\e[0m%} )'
#PS1=$'%{\e[1;32m%}{%{\e[1;31m%}%~%{\e[1;32m%}}%{\e[1;34m%}'${TTY#/dev/(vc|pts|pty)/}$'%# %{\e[0m%}'
#PS1=$'%{\e[1;32m%}{%{%m\e[1;31m%}%~%{\e[1;32m%}}%{\e[1;34m%}'${TTY#/dev/(vc|pts|pty)/}$'%# %{\e[0m%}'
export FTPPROMPT='%M\ %/#\ '
export FTPRPROMPT=%n
export DIRSTACKSIZE=25
export GREP_OPTIONS=--color
#LS_OPTIONS=( --color=auto -F -T 0 -v);
LS_OPTIONS=( --color=auto -F -T 0);
export LS_OPTIONS
alias ls='ls $LS_OPTIONS';
alias ll="command ls -l --hide='*.pyo' --hide='*.pyc' --hide='*.o' \${LS_OPTIONS:s/-A/}"
 if [ -z $DISPLAY ] ; then; else;
   setopt nohup
   setopt nocheckjobs
 fi
 setopt autocd
 setopt autopushd
 setopt correct
 setopt nohistbeep
 setopt ignoreeof
 setopt pathdirs
# setopt Share_History
 setopt Inc_Append_History
 setopt HIST_IGNORE_DUPS
 setopt HIST_IGNORE_ALL_DUPS
 setopt HIST_IGNORE_ALL_DUPS
 setopt HIST_SAVE_NO_DUPS
 setopt NOTIFY
 #setopt AUTO_CONTINUE
 setopt HIST_IGNORE_SPACE
 setopt HIST_REDUCE_BLANKS
 setopt PUSHD_MINUS
 unsetopt beep
 setopt extendedglob

zmodload zsh/mathfunc
 zmodload zsh/complete
 zmodload zsh/compctl
 zmodload zsh/complist

# The following lines were added by compinstall

zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z} m:{a-zA-Z}={A-Za-z}' '' 'r:|[._-]=* r:|=*'
zstyle ':completion:*' completer _oldlist _expand _complete _match _approximate
zstyle ':completion:*' file-sort name
zstyle ':completion:*' ignore-parents pwd
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' max-errors 5
zstyle ':completion:*' prompt 'errors: %e'

# End of lines added by compinstall
#zstyle ':completion:*:(cd|chdir|pushd|popd|cp|mv):*' special-dirs ..
zstyle ':completion:*' special-dirs ..
zstyle ':completion:*:functions' ignored-patterns '_*'
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion::complete:cd::directory-stack' menu yes select
zstyle ':completion::complete:*' use-cache 1

bindkey "^X^M"    accept-and-menu-complete
bindkey "^[o"     edit-command-line
bindkey "^[m"     menu-select

export HISTSIZE=10000
export SAVEHIST=10000
export HISTFILE=~/.history

#RPS1='%? %*'
autoload -U compinit promptinit
compinit
promptinit
promptinit; prompt gentoo
autoload zcalc
autoload zmv
autoload zcp
autoload zln
autoload insert-files
zle -N insert-files
  case $TERM in
    *Eterm)
    bindkey "^[^[[2~" yank
    bindkey "^[\M-'"  accept-and-hold
    bindkey "^[[2~"   overwrite-mode
    bindkey "^[[5~"   up-history
    bindkey "^[[3~"   delete-char
    bindkey "^[^[[3~" kill-word
    bindkey "^[[H"    beginning-of-line
    bindkey "^[[F"    end-of-line
    bindkey "^[[6~"   down-history
    ;;
    *xterm*|rxvt|rxvt-unicode|mrxvt|(dt|k)term|screen)
    bindkey "^[^[[2~" yank
    bindkey "^[\M-'"  accept-and-hold
    bindkey "^[[2~"   overwrite-mode
    bindkey "^[[5~"   up-history
    bindkey "^[[3~"   delete-char
    bindkey "^[^[[3~" kill-word
    bindkey "^[[H"    beginning-of-line
    bindkey "^[[F"    end-of-line
    bindkey "^[[6~"   down-history
    bindkey "^[OM"    accept-line
    bindkey "^[[48$"  reverse-menu-complete
    bindkey "^[[24~" describe-key-briefly #f12
    ;;
    *linux)
    bindkey §         reverse-menu-complete
    bindkey -s "^[[25~" "^[^[[2~"
    bindkey -s "^[[26~" "^[^[[3~"
    bindkey "^[^[[3~" kill-word
    bindkey "^[^[[2~" yank
    bindkey "^[\`"    accept-and-hold
    bindkey "^[[3~"   delete-char
    bindkey "^[[2~"   overwrite-mode
    bindkey "^[[1~"   beginning-of-line
    bindkey "^[[4~"   end-of-line
    bindkey "^[[6~"   down-history
    bindkey "^[[5~"   up-history
    ;;
  esac
    bindkey "^[^[[20~" _complete_help
    bindkey "^N" _most_recent_file
    bindkey "^[r"     overwrite-mode
    bindkey "^[^r"    history-incremental-search-forward
    bindkey "^[[20~"  execute-last-named-cmd
    bindkey "^[[21~"  execute-named-cmd
    bindkey "^[[23~"  push-input
    bindkey "^[[24~"  describe-key-briefly
    bindkey "^U"      undo
    bindkey "^Y"      redo
    bindkey "^[f"     insert-files
    bindkey "^[[A"    up-line-or-search
    bindkey "^[[B"    down-line-or-search
    bindkey "^[^[[D"  backward-word
    bindkey "^[^[[C"  forward-word

xterm-title () {
  case $TERM in
    *xterm*|rxvt|(dt|k|E)term)
      print -Pn "\e]2;$1\a\e]1;$1\a"
    ;;
  esac
}

#precmd() {
#  [[ -t 1 ]] || return     # no terminal as output?
#   xterm-title "$(print -Pn "[${TTY#/dev/pts/}] (%D{%d-%m-%G}) {%~}")"
#}

#preexec () { xterm-title "$(print -Pn "[${TTY#/dev/pts/}] (%D{%d-%m-%G}) {%~} [{($1)}]")" }

shuffle() {
  RANDOM=`date +%s`
  (
  while IFS= read -r i; do
    echo $RANDOM$RANDOM "$i";
  done
  ) | sort | sed 's/^[0-9]* //'
}

#man () { if [ -z $DISPLAY ] ; then command man $@; else; aterm +sb -e man $@ &|; fi }
#edit () { if [ -z $DISPLAY ] ; then vim $@; else; gvim $@; fi }

src ()
{
    autoload -U zrecompile
    [ -f ~/.zshrc ] && zrecompile -p ~/.zshrc
    [ -f ~/.zcompdump ] && zrecompile -p ~/.zcompdump
    [ -f ~/.zshrc.zwc.old ] && rm -f ~/.zshrc.zwc.old
    [ -f ~/.zcompdump.zwc.old ] && rm -f ~/.zcompdump.zwc.old
}
stx () { startx &> /dev/null &| }
tarc () { if [ -e $1 ] ; then if [ -n "$1" ] ; then tar cvjf $1.tar.bz2 $1; fi; fi }
tohex () { echo $(( [#16] $1 )) }
periodic () { hash -r }
export PERIOD=120

alias ren='noglob zmv -W'
alias ls.='ls -d .[^.]*'
alias l="ls -al"
alias 'cd..'='cd ..'
alias j='jobs -l'
alias voicemode='
preexec () {
        xterm-title "$(print -Pn "[${TTY#/dev/pts/}] (%D{%d-%m-%G}) {%~} [$1]")"
        print -P "$1" | festival --tts &|
}'
alias novoicemode='precmd () {
        [[ -t 1 ]] || return # no terminal as output?
        xterm-title "$(print -Pn "[${TTY#/dev/pts/}] (%D{%d-%m-%G}) {%~}")"
}
preexec () {
        xterm-title "$(print -Pn "[${TTY#/dev/pts/}] (%D{%d-%m-%G}) {%~} [$1]")"
}'
#Smerge () {emerge -s \^"$@"\$}

alias df='df -h'
hextodec () { echo $(( [#10] 16#$1 ))|sed 's/.*#//' }
dectohex () { echo $(( [#16] $1 ))|sed 's/.*#//' }
dectobin () { echo $(( [#2] $1 ))|sed 's/.*#//' }
hextobin () { echo $(( [#2] 16#$1 ))|sed 's/.*#//' }
bintohex () { echo $(( [#16] 2#$1 ))|sed 's/.*#//' }
setopt noignoreeof
unsetopt promptcr
setopt magicequalsubst

mkcd () {
    test -z "$1" && echo mkcd: no path given && return
    mkdir -p $1
    cd $1
}
PS1=$'%{\e[0;32m%}%m%40<...<%{\e[1;31m%}%~%<<%{\e[1;34m%}'$'%# %{\e[0m%}'
#export DEVKITPPC=/home/xgc/devkitPPC
#export DEVKITPRO=/home/xgc

function waresearch() { locate -ir "${(pj:.*:)${@:gs/ /.*/}}" }
function f() { eval $(echo find;while (test -n "$1") {echo "|grep -i $1"; shift}) }

_my_extended_wordchars='*?_-.[]~=&;!#$%^(){}<>:@,\\';
_my_extended_wordchars_space="${my_extended_wordchars} "
_my_extended_wordchars_slash="${my_extended_wordchars}/"

# is the current position \-quoted ?
function _is_quoted(){
 test "${BUFFER[$CURSOR-1,CURSOR-1]}" = "\\"
}

_unquote-backward-delete-word(){
    while  _is_quoted
      do zle .backward-kill-word
    done
}

_unquote-forward-delete-word(){
    while  _is_quoted
      do zle .kill-word
    done
}

_unquote-backward-word(){
    while  _is_quoted
      do zle .backward-word
    done
}

_unquote-forward-word(){
    while _is_quoted
      do zle .forward-word
    done
}

_backward-delete-to-space() {
    local WORDCHARS=${_my_extended_wordchars_slash}
    zle .backward-kill-word
    _unquote-backward-delete-word
}

_backward-delete-to-/ () {
    local WORDCHARS=${_my_extended_wordchars}
    zle .backward-kill-word
    _unquote-backward-delete-word
}

_forward-delete-to-space() {
    local WORDCHARS=${_my_extended_wordchars_slash}
    zle .kill-word
    _unquote-forward-delete-word
}

_forward-delete-to-/ () {
    local WORDCHARS=${_my_extended_wordchars}
    zle .kill-word
    _unquote-forward-delete-word
}

_backward-to-space() {
    local WORDCHARS=${_my_extended_wordchars_slash}
    zle .backward-word
    _unquote-backward-word
}

_forward-to-space() {
     local WORDCHARS=${_my_extended_wordchars_slash}
     zle .forward-word
     _unquote-forward-word
}

_backward-to-/ () {
    local WORDCHARS=${_my_extended_wordchars}
    zle .backward-word
    _unquote-backward-word
}

_forward-to-/ () {
     local WORDCHARS=${_my_extended_wordchars}
     zle .forward-word
     _unquote-forward-word
}

zle -N _backward-delete-to-/
zle -N _forward-delete-to-/
zle -N _backward-delete-to-space
zle -N _forward-delete-to-space
zle -N _backward-to-/
zle -N _forward-to-/
bindkey '^w'      _backward-delete-to-/
bindkey '^[^w'    _backward-delete-to-space
bindkey "^[^[[D"  _backward-to-/
bindkey "^[^[[C"  _forward-to-/
bindkey "^[^?"    _backward-delete-to-/
bindkey "^[^[[3~" _forward-delete-to-/

bindkey "^[[1;5D" backward-word
bindkey "^[[1;5C" forward-word
#Make things split words by shell arguments, not spaces
autoload -U select-word-style
select-word-style s

zstyle ':completion:*' accept-exact-dirs 'yes'
compdef _gnu_generic rm cp mv df dog localedef watch metaflac ls zsh
function hexdiff () { diff -u$4 <(${3:-hexdump} "$1") <(${3:-hexdump} "$2") }
