#.zshrc
# code to execute at shell startup


#elektra configuration:
#
# should replace aliases, exports and hashes below
#
# Source functions in /etc/profile.d/
#
#for i in /etc/profile.d/* ; do
#    if [ -r "$i" ]; then
#        #echo sourcing $i
#        source $i
#    fi
#done

#some aliases
alias a="sudo aptitude"		# run aptitude
alias o="open-file-by-name"
alias c="copy-files-to-template"
alias d="diff -pruN"		# differences between files
alias r="recode latin1..utf8"	# recode a file
alias s="festival --tts"	# speak something out
alias p='ps -fu $USER'		# show own processes
alias u='uptime'		# show how long system is up
#alias g="git commit -a -m 'formatting'"
alias g="grep"
alias grep="ugrep"
alias up="sudo ifup"
alias down="sudo ifdown"
alias vip="vi -p"
alias no="yes n"		# why not having no too?
alias ls="ls --color=auto"	# make ls colourful
alias sl="ls"			# spell correction of ls too
alias l="ls"			# spell correction of ls
alias s="ls"			# spell correction of ls
alias mv='nocorrect mv'		#
alias cp='nocorrect cp'		#
alias rm='nocorrect rm'		#
alias du="du -h --max-depth=1"	#
alias cd/='cd /'		# forgot a space for cd
alias cd..='cd ..'		# forgot a space for cd
alias mkdir='nocorrect mkdir'	#
alias man='nocorrect man'	#
alias kdb='nocorrect noglob kdb'
alias bin/kdb='nocorrect noglob bin/kdb'
alias kdb-full='nocorrect noglob kdb-full'
alias bin/kdb-full='nocorrect noglob bin/kdb-full'
alias kdb-static='nocorrect noglob kdb-static'
alias bin/kdb-static='nocorrect noglob bin/kdb-static'
alias find='noglob find'	#
alias lintian="lintian -EI --color=auto --pedantic"
alias reprepro="reprepro -b ~reprepro"
alias ssh-add='ssh-add -t 8h'



#autocomplete aliases:
zstyle ':completion:*' completer _expand_alias _complete _ignored




#Vielen Dank für die Vorstellung

# ^A:multiuser on[RET]
# screen -x

# UMFELD Konfiguration man man

# LINUX SYSTEM pwd, ls

# ELEKTRA TOOL ls --elektra-version

alias 0="man man --elektra:MANWIDTH=40"

# KONFIGURATIONSDATEIEN per key/value zugreifen

alias 1='kdb set user/env/override/MANOPT -- "-LC"'

# PROXY ÄNDERN

alias 3="kdb set system/env/override/http_proxy http://proxy.hogege.com:8000"

alias 5="wget --elektra-debug www.complang.tuwien.ac.at"

# MOTIVATION ftp proxy, auch über Konfigurationsdatei im Paper

alias 4="kdb setmeta spec/env/override/ftp_proxy 'override/#0' /env/override/http_proxy"

# Umsetzung

alias 6="kdb get -v /env/override/ftp_proxy"








#alias 5="kdb set user/env/option/debug"

# kann man weglassen
alias 2='kdb mount env.ini /env ni'

# kdb file /env

#pipes stderr
#alias -g P='>&2 2>&1 |'

# Creates a directory and changes into it at one command
function mkcd() {
	[ -n "$1" ] && mkdir -p "$@" && cd "$1"
}

#some hashes
#(more in .zshrc-local or elektra)
hash -d m=/home/user/MyDocs

HISTFILE=${HOME}/.zsh_history	# name of history file
HISTSIZE=500000			# internal history (larger for duplicated events)
SAVEHIST=450000			# history in files
DIRSTACKSIZE=10			# stack of directories
MAIL=/var/mail/$USERNAME	# where are new mails?
MAILCHECK=30			# check mails every 30 sec
#REPLYTO=ich@markus-raab.org	# reply to
LOGCHECK=30			# check login/logout every 30 sec

unset TMOUT			# don't timeout the session

bindkey -v                      # vi key bindings

#bindkey "^[[A" history-beginning-search-backward
#bindkey "^[[B" history-beginning-search-forward
# Use up and down key to search in the history with the current text
# !word<tab> will autocomplete in the history
# (up and down key can be used afterwards too)
# use <ESC> + / to search backwards in the history (? to search forward)
# (n(next) and N(previous) will scroll in the history in this mode)


setopt always_to_end		# move to end of word when completing
setopt append_history		# don't overwrite history file (multiple!)
setopt share_history		# share history between multiple sessions
setopt auto_cd			# change to directory when entering it as command
setopt auto_menu		# use menu completion
setopt auto_pushd		# cd will push old directory on stack
setopt NO_hup			# don't HUP running jobs when shell exits
setopt NO_beep			# don't beep around
setopt NO_hist_beep		# also don't beep at no history
setopt NO_list_beep		#
setopt correct_all		# correct all arguments in a line
setopt extended_glob		# tread ~, ^ as part of patterns
setopt extended_history		# save timestamps of history
setopt glob_complete		# cycle through glob possibilities
setopt hist_expire_dups_first	# duplicate internal events
setopt hist_find_no_dups	# but don't find duplicates
setopt hist_ignore_all_dups	# and ignore them
setopt hist_ignore_dups		# and don't put same commands to history
setopt hist_ignore_space	# first character a space -> don't put to history
setopt hist_reduce_blanks	# reduce blanks from command line in history
setopt hist_save_no_dups	# older commands that duplicate are omitted
setopt hist_verify		# perform history expansion and reload line
setopt interactive_comments	# i always want comments
setopt list_packed		# put list in columns
setopt list_types		# show trailing identifying mark
setopt null_glob		# delete globs without match instead of asking
setopt pushd_ignore_dups	# ignore dups on directory stack
setopt pushd_silent		# be silent after pushd and popd
#setopt completion-ignore-case


zstyle ':completion:*:cd:*' ignore-parents parent pwd #cd will never select the parent directory (e.g.: cd ../<TAB>):

# prompt, right prompt, don't see XX possibilities and spelling prompt
EXITCODE="%(?..%?%1v )"
#old one without exit codes:
#PS1=$'%{\e[0;36m%}%n@%m:%4c%1v%{\e[0m%}> '

# NEW ONE:
PS1=$'%(?..%?%1v )%{\e[0;36m%}%n@%m:%4c%1v%{\e[0m%}> '
RPS1=$'%{\e[0;36m%}%D{%A %T}%{\e[0m%}'

# FOR asciinema:
#PS1=$'%(?..%?%1v )%{\e[0;36m%}%4c%1v%{\e[0m%}> '
#RPS1=
#alias sudo='nocorrect sudo'
LISTPROMPT=''
SPROMPT='zsh: correct '%R' to '%r' ? ([Y]es/[N]o/[E]dit/[A]bort) '
LPDEST=lj

#activate coredumps
ulimit -c unlimited

#load other modules from ~/.zshfiles
fpath=(~/.zshfiles $fpath)
autoload -U ~/.zshfiles*(:t)

#load compinit
autoload -U compinit		# full features tab completion
compinit -C			# start the tab completion
zmodload -i zsh/complist	# Color completion (For menu selection)

#load local files
. ~/.zshrc-local
. ~/.env.sh

#list running screens
#if [[ -x $(which screen) ]]
#then
#    ZSHRC_SCREENLIST=(${${(M)${(f)"$(screen -ls)"}:#(#s)?:space:##([0-9]##).*}/(#b)?:space:#([0-9]##).*/$match[1]})
#    if [[ $#ZSHRC_SCREENLIST -ge 1 ]]
#    then
#        echo "There are $#ZSHRC_SCREENLIST screens running. $ZSHRC_SCREENLIST"
#    fi
#fi

#for i in viins vicmd; do
#	bindkey -M "$i" "${key[Up]}" vi-up-line-or-history
#	bindkey -M "$i" "${key[Down]}" vi-down-line-or-history
#done
#unset i

#[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" history-search-backward
#[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" history-search-forward

#switch between vim and shell
fancy-ctrl-z () {
	if [[ $#BUFFER -eq 0 ]]; then
		BUFFER="fg"
		zle accept-line
	else
		zle push-input
		zle clear-screen
	fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z

autoload up-line-or-beginning-search
autoload down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search

[[ -n "${key[Up]}"      ]]  && bindkey   "${key[Up]}"       up-line-or-beginning-search
[[ -n "${key[Down]}"    ]]  && bindkey   "${key[Down]}"    down-line-or-beginning-search

#start up screen, if not already in
#if [ -z $STY ]; then
#        screen -D -R
#fi