# start tmux with shell
#[[ -z $TMUX ]] && exec tmux
# autologout when no commands were entered for 30 min.
export TMOUT=1800
export EDITOR='vi'
export PAGER='less'
export LESS='-giMrRAK'
export LESSOPEN='|/usr/bin/lesspipe.sh %s'
export GREP_COLOR='0;31'
export LS_COLORS='di=32:ln=35:so=33:pi=31:ex=34:bd=34;40:cd=35;40:su=30;42:sg=37;42:tw=30;46:ow=31;46'
export LSCOLORS='cxfxdxbxexeafaachcagbg'
export CLICOLOR='1'
PROMPT=' %B%F{green}%C %f%#%b '
WORDCHARS='*?_-.[]~'
HISTFILE=$HOME/.zsh_history
HISTSIZE=SAVEHIST=100000
LISTMAX=999
setopt notify # report the status of background jobs immediately
setopt correct # try to correct the spelling of commands
setopt auto_cd # if the command is the name of a directory, perform cd
setopt auto_list # automatically list choices on an ambiguous completion
setopt auto_continue # unsuspend suspended jobs on `disown' command
setopt chase_links # show symlink real value when cd into it
setopt interactive_comments # allow comments in interactive shells
setopt cdablevars # when argument to cd is a parameter whose value is a valid directory, perform cd
setopt append_history # append history to the history file, rather than replace it
setopt extended_history # save command beginning timestamp and the duration
setopt hist_reduce_blanks # remove superfluous blanks from history
setopt hist_ignore_all_dups # if new command duplicates an older one, remove the older from history
setopt hist_ignore_space # do not save line to the history list when first character is a space
setopt hist_verify # perform history expansion and reload the line into the editing buffer
setopt share_history # share history between all sessions
setopt bang_hist # perform textual history expansion, treating the character `!' specially
setopt rec_exact # recognize exact matches even if they are ambiguous
setopt auto_pushd # cd push the old directory onto the directory stack
setopt pushd_ignore_dups # don't push multiple copies of the same directory onto the directory stack
setopt check_jobs # report the status of jobs before exiting
setopt long_list_jobs # list jobs in long format by default
setopt glob_complete # do not insert all the words resulting from the wildcard expansion
setopt extended_glob # treat the `#', `~' and `^' characters as part of patterns
#setopt dotglob # completion shows filenames beginning with a dot
unsetopt nomatch # do not warn when using glob with no matches
unsetopt bg_nice # do not run all background jobs at a lower priority
unsetopt hup # do not kill running jobs when shell exits
unsetopt checkjobs # don't complain about still running background jobs
unsetopt auto_remove_slash # disable automatic removing of slash
unsetopt prompt_sp # do not preserve a partial line
unsetopt auto_menu # do not use menu completion
unsetopt always_last_prompt # print completion suggestions above prompt
unsetopt beep # disable beep
autoload -Uz compinit; compinit
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true
zstyle ':completion:*' use-cache true
zstyle ':completion:*' cache-path ~/.zsh/
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' completer _expand _complete _match
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' file-sort links reverse
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*:commands' rehash true
autoload -U select-word-style; select-word-style b
zstyle ':zle:*' word-chars "$WORDCHARS"
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -U $USER'
zstyle ':completion:*:functions' ignored-patterns '_*'
# emacs keybindings
bindkey -e
# alt+z/shift+alt+z
bindkey '\ez' undo
bindkey '\eZ' redo
# del key
bindkey '\e[3~' delete-char
# alt+del
bindkey '\e[3;3~' kill-word
# alt+left/right
bindkey '\e[1;3D' backward-kill-word
bindkey '\e[1;3C' kill-word
# alt+up/down
bindkey '\e[1;3A' backward-kill-line
bindkey '\e[1;3B' kill-line
# ctrl+left/right
bindkey '\e[1;5D' backward-word
bindkey '\e[1;5C' forward-word
# ctrl+up/down
bindkey '\e[1;5A' beginning-of-line
bindkey '\e[1;5B' end-of-line
# end/home
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
bindkey '\e[H' beginning-of-line
bindkey '\e[F' end-of-line
# pgup/pgdown
bindkey '\e[5~' up-line-or-history
bindkey '\e[6~' down-line-or-history
# up/down to autocomplete from history, moving cursor to end of line
autoload -U history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey '\e[A' history-beginning-search-backward-end
bindkey '\e[B' history-beginning-search-forward-end
bindkey '\eOA' history-beginning-search-backward-end
bindkey '\eOB' history-beginning-search-forward-end
# ctrl+alt+up/down to search history
bindkey '\e[1;7A' history-incremental-search-backward
bindkey '\e[1;7B' history-incremental-search-forward
# shift+tab - reverse menu
bindkey '\e[Z' reverse-menu-complete
# list dir with TAB when there are only spaces/no text before cursor
# or complete words, that are before cursor only (like in tcsh)
function tcsh_autolist() {
if [[ -z ${LBUFFER// } ]]
then BUFFER='ls ' CURSOR=3 zle list-choices
else zle expand-or-complete-prefix
fi }
zle -N tcsh_autolist
bindkey '\CI' tcsh_autolist
# ctrl+b - return to previous dir
function back() {
echo
pushd +1
zle reset-prompt }
zle -N back
bindkey '\Cb' back
# ctrl+f - resume job
function foreground() {
CURSOR=0
LBUFFER+="fg %"
zle accept-line }
zle -N foreground
bindkey '\CF' foreground
# completion system recognizes 's' as 'sudo'
compdef s='sudo'
# alias -es
alias s='sudo'
alias ss='sudo -s'
alias c='cat'
alias r='readlink -f'
alias i='img2xterm'
alias history='fc -l -E 1'
alias h='fc -l -E -25'
alias j='jobs -l'
alias .='pwd'
alias ...='../..'
alias ls='ls -F'
alias la='ls -a'
alias ll='ls -lht'
alias rm='rm -I'
alias grep='grep --color -I'
alias g='\grep --color -i'
alias v='vi'
alias e='builtin echo'
alias du='du -h'
alias mkdir='mkdir -p'
alias stat='stat -x'