# The following lines were added by compinstall

zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' group-name ''
zstyle ':completion:*' ignore-parents parent pwd .. directory
zstyle ':completion:*' insert-unambiguous true
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z} m:{a-zA-Z}={A-Za-z}' 'r:|[._-]=** r:|=**' 'l:|=* r:|=*'
zstyle ':completion:*' max-errors 3 numeric
zstyle ':completion:*' menu select=0
zstyle ':completion:*' prompt '%d)'
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose yes
zstyle :compinstall filename '/home/tinou/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall

# used alone : prints all different filetypes found in current dir
# prints files corresponding to filetype
# options are passed to ls
# successives greps on the file * are performed :
# ft [-lsoptions] [filetype keywords...]

ft(){
	lsopt=

	while [ "`echo $1 | grep '-'`" ]; do
		lsopt="$1"
		shift
	done

	if [ -d "$1" ]; then
		cd "$1"
		shift
	fi
	if [ -z "$1" ]; then
			file -nb * | sort | uniq
	else
		lines="`file * | grep -i $1`"
		for i in "$@"; do
			lines="`echo $lines | grep -i $i`"
		done
		if [ "$lines" ]; then
			if [ "$fileo" ]; then
				ret="$lines"
			else
				files="`echo $lines | cut -sd: -f1 | tr "\n" " "`"
				ret=`ls $lsopt \`echo $files\` | sort | uniq`
			fi
			echo "$ret"
		else
			echo "no such type from this directory" >&2
		fi
	fi
}

# as v (ls -l) appending the file info at the end of each line
f(){
	echo "" > /tmp/.ft_$UID
	file -b * >> /tmp/.ft_$UID
	output=`ls -1 --color=always | paste -d":" - /tmp/.ft_$UID`

	# is there something to filter ?
	while [ "$1" ]; do
		output=`echo $output | grep $1`
		shift
	done
	if [ "$output" ]; then
		echo $output
	else
		echo "no such type from this directory" >&2
	fi
}

autoload -U promptinit
promptinit
# prompt walters

# HISTFILE=~/.zsh-history.$ZSH_VERSION
HISTFILE=~/.zsh-history
HISTSIZE=500000
SAVEHIST=500000
# setopt hist_ignore_all_dups hist_reduce_blanks \
# hist_save_no_dups hist_verify inc_append_history no_bang_hist share_history
setopt hist_ignore_all_dups hist_reduce_blanks \
hist_save_no_dups inc_append_history \
extended_history share_history multios

export PATH=$PATH:/sbin:/usr/sbin:/home/tinou/hack/scripts
export EDITOR="gvim"
export SHELL=/bin/zsh
alias ls='ls --color=auto'
alias v='ls -l'
alias ll='ls -hl'
alias fc='fc -e vim'
alias hash='hash -v'
alias dt='displayterminal'
alias aafire='aafire -driver slang'
alias fire='aafire'
alias xvim='xvim.sh'
alias xvi='xvim'
alias grub='grub-install hd0'
alias unmerge='emerge -aC'
alias unemerge=unmerge
alias man='man -P "less -si"'
alias cp='cp -g'

# used alone : prints all different filetypes found in current dir
# prints files corresponding to filetype
# options are passed to ls
# successives greps on the file * are performed :
# ft [-lsoptions] [filetype keywords...]

ft(){
	lsopt=

	while [ "`echo $1 | grep '-'`" ]; do
		lsopt="$1"
		shift
	done

	if [ -d "$1" ]; then
		cd "$1"
		shift
	fi
	if [ -z "$1" ]; then
			file -nb * | sort | uniq
	else
		lines="`file * | grep -i $1`"
		for i in "$@"; do
			lines="`echo $lines | grep -i $i`"
		done
		if [ "$lines" ]; then
			if [ "$fileo" ]; then
				ret="$lines"
			else
				files="`echo $lines | cut -sd: -f1 | tr "\n" " "`"
				ret=`ls $lsopt \`echo $files\` | sort | uniq`
			fi
			echo "$ret"
		else
			echo "no such type from this directory" >&2
		fi
	fi
}

# as v (ls -l) appending the file info at the end of each line
f(){
	pouetproutecacaRt12="rien"
	echo "" > /tmp/.ft_$UID
	file -b * >> /tmp/.ft_$UID
	output=`ls -1 --color=always | paste -d":" - /tmp/.ft_$UID`

	# is there something to filter ?
	while [ "$1" ]; do
		output=`echo $output | grep $1`
		shift
	done
	if [ "$output" ]; then
		echo $output
	else
		echo "no such type from this directory" >&2
	fi
}


autoload -U compinit
compinit
# End of lines added by compinstall
# The following lines were added by compinstall

zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' group-name ''
zstyle ':completion:*' ignore-parents parent pwd .. directory
zstyle ':completion:*' insert-unambiguous true
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z} m:{a-zA-Z}={A-Za-z}' 'r:|[._-]=** r:|=**' 'l:|=* r:|=*'
zstyle ':completion:*' max-errors 3 numeric
zstyle ':completion:*' menu select=0
zstyle ':completion:*' prompt '%d)'
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose yes
zstyle :compinstall filename '/home/tinou/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall
autoload -U promptinit
promptinit
# prompt walters

HISTSIZE=500
SAVEHIST=50000
# setopt hist_ignore_all_dups hist_reduce_blanks \
# hist_save_no_dups hist_verify inc_append_history no_bang_hist share_history
setopt hist_ignore_all_dups hist_reduce_blanks \
hist_save_no_dups inc_append_history extended_history share_history
WATCH=all
LOGCHECK=20

export PATH=$PATH:/sbin:/home/tinou/hack/scripts
export EDITOR="gvim"
export SHELL=/bin/zsh
alias ls='ls --color=auto'
alias v='ls -l'
alias ll='ls -hl'
alias fc='fc -e vim'
alias hash='hash -v'
alias dt='displayterminal'
alias aafire='aafire -driver slang'
alias fire='aafire'
alias xvim='xvim.sh'
alias xvi='xvim'
alias startx='startx |& tee xlog'

# /home/tinou/hack/scripts/wt \
#	 "Terminal <`cat /tmp/$UID.iceTerms 2>&-`> (zsh:$$)" 2>&-

function preexec(){
	chpwd
	lastcmd=$1
	if [ "$TERM" != "linux" ]; then
		# echo -n "\033]0;$USER@$HOST $PWD $1\007"
		wt "$lastcmd    ; $USER@$HOST:$PWD" 2>&-
	fi
}
# function precmd(){
	# echo "$1 $2 $3 $0"
	# lastcmd=$1
	# if [ "$TERM" != "linux" ]; then
		# # echo -n "\033]0;$USER@$HOST $PWD $1\007"
		# wt "$USER@$HOST $PWD $lastcmd"
	# fi
# }
function precmd() {
  [[ -t 1 ]] || return
  case $TERM in
    sun-cmd) print -Pn "\e]l%~\e\\"
      ;;
    *xterm*|rxvt|(dt|k|E)term) print -Pn "\e]2;% zsh $$ %n@%m: %~\a"
      ;;
  esac
}



# To discover the proper keys, in vi mode type: ^v then the key
bindkey '^[[3~' delete-char
bindkey '^[[7~' beginning-of-line
bindkey '^[[8~' end-of-line

# set cmd mode default :
# zle-line-init() { zle -K vicmd; }
# zle -N zle-line-init
# PS1=%\*\ %\!\ %B%(?..[%?] )%b%n@%U%m%u\>\ 
##########################################################
# from Flouf
# FIXME : remove things above that appear below
##########################################################
# PS1=$'%h %{\e[22;44m%}%n@%m%{\e[00m%} %{\e[01;36m%}%0~%{\e[01;37m%} %# %{\e[00m%}'
PS1=$'%h %{\e[22;44m%}%n@%m%{\e[00m%} %# %{\e[00m%}'
# RPROMPT=$'%{\e[01;36m%}%0~%{\e[01;37m%} %{\e[00m%}'

## faq 3.6 how do i automatically display the directory in my xterm title bar?
## http://zsh.sourceforge.net/faq/zshfaq03.html#l22
##
## i modified the xterm version because it was too plain.
chpwd() {
  [[ -t 1 ]] || return
  case $term in
    sun-cmd) print -pn "\e]l%~\e\\"
      ;;
    *xterm*|rxvt|(dt|a|k|e)term) print -Pn "\e]2;% %n@%m: %~\a"
      ;;
  esac
}

### Use cache
## Some functions, like _apt and _dpkg, are very slow. You can use a cache in
## order to proxy the list of results (like the list of available debian
## packages)
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache

## Prevent CVS files/directories from being completed
zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'

## I use dvorak, so correct spelling mistakes that a dvorak user would make
setopt dvorak

## Extended history.
## Instead of just a list of commands, append it with this:
## ':<beginning time since epoch>:<elapsed seconds>:<command>'.
setopt extended_history

## Automatically append directories to the push/pop list
setopt auto_pushd

## Maximum size of the directory stack
DIRSTACKSIZE=50

## From resolve's config (http://repose.cx/conf/.zshrc)
setopt extended_glob            # Weird & wacky pattern matching - yay zsh!
setopt complete_in_word         # Not just at the end
setopt always_to_end            # When complete from middle, move cursor
setopt correct                  # Spelling correction
# setopt hist_verify              # When using ! cmds, confirm first
setopt interactive_comments     # Escape commands so I can use them later
setopt print_exit_value         # Alert me if something's failed

## Anti-aliasing in the two toolkits
## Use this type of assignment to set the variable if not already set
(( ${+QT_XFT} )) || export QT_XFT=1
(( ${+GDK_USE_XFT} )) || export GDK_USE_XFT=1

##########################################################
# prompt walters
prompt adam2
