Skip to content

Instantly share code, notes, and snippets.

@vodik
Created April 29, 2014 15:26
Show Gist options
  • Save vodik/11403625 to your computer and use it in GitHub Desktop.
Save vodik/11403625 to your computer and use it in GitHub Desktop.
zshrc
autoload -U vcs_info
autoload -U colors && colors
autoload -U compinit && compinit
autoload zsh/terminfo
HISTFILE=$HOME/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
HISTIGNORE=' '
# smart urls
autoload -U url-quote-magic
zle -N self-insert url-quote-magic
# changing directories
setopt auto_cd \
auto_pushd \
cdable_vars \
chase_links \
pushd_ignore_dups \
pushd_silent \
pushd_to_home
# completion
setopt always_to_end \
auto_menu \
auto_name_dirs \
auto_param_keys \
auto_param_slash \
auto_remove_slash \
complete_aliases \
complete_in_word \
list_ambiguous \
list_packed
unsetopt menu_complete
# expansion and globbing
setopt brace_ccl \
extended_glob \
long_list_jobs \
multios \
prompt_subst
# input/output
setopt correct \
interactive_comments \
rc_quotes \
short_loops
unsetopt flowcontrol
# job control
setopt bg_nice
# zle
unsetopt beep
# prompt
setopt prompt_subst
#history
setopt append_history \
extended_history \
hist_expire_dups_first \
hist_ignore_dups \
hist_ignore_space \
hist_verify \
inc_append_history \
share_history
export SUDO_PROMPT=$'\e[31mSUDO\e[m password for \e[34m%p\e[m: '
export LESS_TERMCAP_mb=$'\e[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\e[01;31m' # begin bold
export LESS_TERMCAP_me=$'\e[0m' # end mode
export LESS_TERMCAP_so=$'\e[01;36m' # begin standout-mode
export LESS_TERMCAP_se=$'\e[0m' # end standout-mode
export LESS_TERMCAP_us=$'\e[00;36m' # begin underline
export LESS_TERMCAP_ue=$'\e[0m' # end underline
[[ -f ~/etc/dircolors/dircolors ]] && \
source <(dircolors ~/etc/dircolors/dircolors)
# {{{1 TERM
[[ $TERM == xterm ]] && export TERM=xterm-256color
case $TERM in
termite|vte*|xterm*|rxvt*)
function precmd {
print -Pn '\e];%n@%m %~\a'
}
function preexec {
local cmd=${1[(wr)^(*=*|sudo|ssh|-*)]}
print -Pn "\e];$cmd:q\a"
}
;;
esac
# }}}
# {{{1 ALIAS
alias ls='ls -FNh --tabsize=0 --color=auto --show-control-chars --group-directories-first'
alias ll='ls -l'
alias la='ls -a'
alias lla='ls -la'
alias tree='tree -C'
# }}}
# {{{1 FUNCTIONS
# bg on empty line, push-input on non-empty line
function fancy-ctrl-z {
if [[ $#BUFFER -eq 0 ]]; then
bg
zle redisplay
else
zle push-input
fi
};
function zle-line-init zle-keymap-select {
vimode="${${KEYMAP/vicmd/c}/(main|viins)/i}"
zle reset-prompt
}
zle -N fancy-ctrl-z
zle -N zle-line-init
zle -N zle-keymap-select
# }}}
# {{{1 KEYMAPPING
# make zsh/terminfo work for terms with application and cursor modes
case "$TERM" in
vte*|xterm*)
zle-line-init() { zle-keymap-select; echoti smkx }
zle-line-finish() { echoti rmkx }
zle -N zle-line-init
zle -N zle-line-finish
;;
esac
# vi editing mode
bindkey -v
# shift-tab
if [[ -n $terminfo[kcbt] ]]; then
bindkey "$terminfo[kcbt]" reverse-menu-complete
fi
# do history expansion on space
bindkey ' ' magic-space
# delete
if [[ -n $terminfo[kdch1] ]]; then
bindkey "$terminfo[kdch1]" delete-char
bindkey -M vicmd "$terminfo[kdch1]" vi-delete-char
fi
# insert
if [[ -n $terminfo[kich1] ]]; then
bindkey "$terminfo[kich1]" overwrite-mode
bindkey -M vicmd "$terminfo[kich1]" vi-insert
fi
# home
if [[ -n $terminfo[khome] ]]; then
bindkey "$terminfo[khome]" vi-beginning-of-line
bindkey -M vicmd "$terminfo[khome]" vi-beginning-of-line
fi
# end
if [[ -n $terminfo[kend] ]]; then
bindkey "$terminfo[kend]" vi-end-of-line
bindkey -M vicmd "$terminfo[kend]" vi-end-of-line
fi
# backspace (and <C-h>)
if [[ -n $terminfo[kbs] ]]; then
bindkey "$terminfo[kbs]" backward-delete-char
bindkey -M vicmd "$terminfo[kbs]" backward-char
fi
bindkey '^H' backward-delete-char
bindkey -M vicmd '^H' backward-char
# page up (and <C-b> in vicmd)
if [[ -n $terminfo[kpp] ]]; then
bindkey "$terminfo[kpp]" beginning-of-buffer-or-history
bindkey -M vicmd "$terminfo[kpp]" beginning-of-buffer-or-history
fi
bindkey -M vicmd '^B' beginning-of-buffer-or-history
# page down (and <C-f> in vicmd)
if [[ -n $terminfo[knp] ]]; then
bindkey "$terminfo[knp]" end-of-buffer-or-history
bindkey -M vicmd "$terminfo[knp]" end-of-buffer-or-history
fi
bindkey -M vicmd '^F' end-of-buffer-or-history
# up arrow (history search)
if [[ -n $terminfo[kcuu1] ]]; then
bindkey "$terminfo[kcuu1]" history-beginning-search-backward
bindkey -M vicmd "$terminfo[kcuu1]" history-beginning-search-backward
fi
bindkey '^[[A' history-beginning-search-backward
# down arrow (history search)
if [[ -n $terminfo[kcud1] ]]; then
bindkey "$terminfo[kcud1]" history-beginning-search-forward
bindkey -M vicmd "$terminfo[kcud1]" history-beginning-search-forward
fi
bindkey '^[[B' history-beginning-search-forward
# left arrow (whichwrap)
if [[ -n $terminfo[kcub1] ]]; then
bindkey "$terminfo[kcub1]" backward-char
bindkey -M vicmd "$terminfo[kcub1]" backward-char
fi
# right arrow (whichwrap)
if [[ -n $terminfo[kcuf1] ]]; then
bindkey "$terminfo[kcuf1]" forward-char
bindkey -M vicmd "$terminfo[kcuf1]" forward-char
fi
# shift-left
if [[ -n $terminfo[kLFT] ]]; then
bindkey "$terminfo[kLFT]" vi-backward-word
bindkey -M vicmd "$terminfo[kLFT]" vi-backward-word
fi
# shift-right
if [[ -n $terminfo[kRIT] ]]; then
bindkey "$terminfo[kRIT]" vi-forward-word
bindkey -M vicmd "$terminfo[kRIT]" vi-forward-word
fi
# ctrl-left
bindkey '^[[1;5D' vi-backward-blank-word
bindkey '^[[1;5C' vi-forward-blank-word
bindkey '^i' expand-or-complete-prefix
bindkey '^W' backward-kill-word
bindkey -M vicmd 'h' backward-char
bindkey -M vicmd 'l' forward-char
bindkey -M vicmd '^R' redo
bindkey -M vicmd 'u' undo
bindkey -M vicmd 'ga' what-cursor-position
bindkey -M vicmd 'v' edit-command-line
# fancy <C-z>
bindkey '^Z' fancy-ctrl-z
bindkey -M vicmd '^Z' fancy-ctrl-z
# buffer stack access
bindkey '^w' push-line
bindkey '^e' get-line
# }}}
# {{{1 ZSTYLE
_force_rehash() {
(( CURRENT = 1 )) && rehash
return 1
}
zstyle ':completion::complete:*' use-cache on
# Group matches and describe.
zstyle ':completion:*:*:*:*:*' menu yes select
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:corrections' format '%B%F{green}>> %d (errors: %e)%f%b'
zstyle ':completion:*:descriptions' format '%B%F{magenta}>> %d%f%b'
zstyle ':completion:*:messages' format '%B%F{cyan}>> %d%f%b'
zstyle ':completion:*:warnings' format '%B%F{red}>> no matches found%f%b'
zstyle ':completion:*:default' list-prompt '%B%S%M matches%s%b'
zstyle ':completion:*' format '%B%F{cyan}>> %d%f%b'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' verbose yes
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete _match _approximate
zstyle ':completion:*' menu select=2
zstyle ':completion:*:functions' ignored-patterns '_*'
zstyle ':completion:*:match:*' original only
zstyle ':completion:*:approximate:*' max-errors 1 numeric
zstyle ':completion:*:*:*:users' ignored-patterns \
bin daemon mail ftp http nobody dbus avahi named git bitlbee mpd \
rtkit ntp usbmux gdm
# COMMANDS {{{2
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories
zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'users' 'expand'
zstyle ':completion:*' squeeze-slashes true
# vim zstyle
zstyle ':completion:*:*:(vim|gvim):*:*files' ignored-patterns '*~|*.(old|bak|o|hi)'
zstyle ':completion:*:*:(vim|gvim):*:*files' file-sort modification
zstyle ':completion:*:*:(vim|gvim):*' file-sort modification
zstyle ':completion:*:*:(vim|gvim):*' tag-order files
# kill zstyle
zstyle ':completion:*:*:kill:*' command 'ps -e -o pid,%cpu,tty,cputime,cmd'
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
zstyle ':completion:*:*:kill:*' insert-ids single
# man
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.(^1*)' insert-sections true
# ssh/scp/rsync
zstyle ':completion:*:(scp|rsync):*' tag-order 'hosts:-host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
zstyle ':completion:*:(scp|rsync):*' group-order files all-files hosts-domain hosts-host hosts-ipaddr
zstyle ':completion:*:ssh:*' tag-order 'hosts:-host hosts:-domain:domain hosts:-ipaddr:ip\ address *'
zstyle ':completion:*:ssh:*' group-order hosts-domain hosts-host users hosts-ipaddr
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*.*' loopback localhost
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^*.*' '*@*'
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^<->.<->.<->.<->' '127.0.0.<->'
# }}}
# VCS {{{2
zstyle ':vcs_info:*' enable git cvs svn
zstyle ':vcs_info:*' actionformats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
zstyle ':vcs_info:*' formats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
# }}}1
function vcs_info_wrapper {
vcs_info
[[ -n "$vcs_info_msg_0_" ]] && echo " %{$fg[grey]%}${vcs_info_msg_0_/ /}%{$reset_color%}"
}
PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%1~%{$reset_color%}$(vcs_info_wrapper) $ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment