]> Sergey Matveev's repositories - dotfiles.git/blob - zsh/.zshrc
11507317a230d43679b2009329f41657ec0bb04f
[dotfiles.git] / zsh / .zshrc
1 # vim: foldmethod=marker:foldlevel=0
2
3 # Basic options {{{
4 setopt INTERACTIVE_COMMENTS
5 setopt GLOB_STAR_SHORT GLOB_DOTS EXTENDED_GLOB
6 setopt NO_NOMATCH
7 setopt AUTO_PUSHD PUSHD_IGNORE_DUPS
8
9 setopt RM_STAR_SILENT
10 export LISTMAX=9999
11 # }}}
12
13 # History options {{{
14 setopt APPEND_HISTORY SHARE_HISTORY INC_APPEND_HISTORY HIST_IGNORE_ALL_DUPS
15 setopt HIST_IGNORE_SPACE
16 HISTORY_IGNORE="(yt* *|t *|t|mmfileget *|arr|rss)"
17 # }}}
18
19 # Vi mode {{{
20 bindkey -v
21 export KEYTIMEOUT=1
22 # }}}
23
24 # Home/end {{{
25 bindkey "^[[1~" beginning-of-line
26 bindkey "^[[4~" end-of-line
27 # }}}
28
29 # Command-line editing {{{
30 autoload -U edit-command-line
31 zle -N edit-command-line
32 bindkey -M vicmd v edit-command-line
33 # }}}
34
35 # History search {{{
36 autoload -U history-search-end
37 zle -N history-beginning-search-backward-end history-search-end
38 zle -N history-beginning-search-forward-end history-search-end
39 bindkey "^[[A" history-beginning-search-backward-end
40 bindkey "^[[B" history-beginning-search-forward-end
41
42 beginning-history-incremental-pattern-search-backward() {
43     zle history-incremental-pattern-search-backward $(echo $BUFFER | sed "s/ /*/g")
44 }
45 zle -N beginning-history-incremental-pattern-search-backward
46 bindkey "^[[1;2A" beginning-history-incremental-pattern-search-backward
47 bindkey -M isearch "^[[A" history-incremental-pattern-search-backward
48 bindkey -M isearch "^[[B" history-incremental-pattern-search-forward
49 # }}}
50
51 # Prompt {{{
52 function zle-line-init zle-keymap-select {
53     mode_vi="${${KEYMAP/vicmd/+}/(main|viins)/-}"
54     [ $timer ] && timer_show=$(( $SECONDS - $timer ))
55     prompt="%2~|"
56     prompt+="%U${timer_show}%u|"
57     prompt+="%B%?%b"
58     prompt+="${mode_vi}"
59     prompt+="%B%F{magenta}%#%f%b "
60     PS1="$prompt"
61     zle reset-prompt
62 }
63 zle -N zle-line-init
64 zle -N zle-keymap-select
65
66 preexec() {
67     timer=$SECONDS
68 }
69
70 precmd() {
71     printf "\a\033]2;\033\\"
72 }
73 # }}}
74
75 # Aliases {{{
76 alias l="ls -AF "
77 alias ll="ls -AFl "
78 alias ssh="TERM=xterm ssh"
79 alias vi="vim"
80 alias more="less"
81 alias m="less "
82 alias -g M="| less"
83 alias -g W="| wc -l"
84 alias mc="mc --nomouse"
85 alias sent="mutt -f =sent-`date '+%y-%m'`"
86
87 f() {
88     # find . -name "*$1*" -print
89     print -C 1 **$1*
90 }
91
92 ssht() {
93     ssh -C -t "$1" tmux attach -t0
94 }
95 alias sshnm="ssh -S none"
96 # }}}
97
98 # Faster movement {{{
99 cddotdot() {
100     cd ..
101     pwd
102     zle reset-prompt
103 }
104 zle -N cddotdot
105 bindkey "\eOQ" cddotdot # F2
106
107 pushdquiet() {
108     popd
109     zle reset-prompt
110 }
111 zle -N pushdquiet
112 bindkey "\eOS" pushdquiet # F4
113 # }}}
114
115 # Git {{{
116 alias Ga="git add"
117 alias Gb="git branch"
118 alias Gc="git checkout"
119 alias Gd="git diff"
120 alias Gdc="git diff --cached"
121 alias Gs="git show --show-signature"
122 alias Gm="git diff --name-only --diff-filter=M"
123 alias Gam="git commit --amend"
124
125 git_common="--oneline --abbrev-commit"
126 alias Gl="git log $git_common --graph --decorate=short"
127 alias Gr="git --no-pager log $git_common -n 20 | perl -ne 'print \"@~\$n \$_\"; \$n++'"
128 alias Grr="git --no-pager log $git_common --graph -n 1024 | vi -c 'setlocal filetype=gitrebase buftype=nofile noswapfile' -"
129
130 bindkey -s "\eOR" " git status --short\n" # F3
131 # }}}
132
133 # grep {{{
134 GREP=/usr/local/bin/grep
135 GREP_ARGS="--color=always --with-filename --line-number --dereference-recursive"
136 LESS_COLORED="less --RAW-CONTROL-CHARS"
137 g() {
138     $GREP ${=GREP_ARGS} $@ | ${=LESS_COLORED}
139 }
140 GS() {
141     $GREP ${=GREP_ARGS} $@ | sort --numeric-sort | ${=LESS_COLORED}
142 }
143 alias -g G="| $GREP --color"
144 alias gg="git grep "
145 # }}}
146
147 # GPG agent {{{
148 GPG_TTY=$(tty)
149 export GPG_TTY
150 # }}}
151
152 # Virtualenv {{{
153 venv() {
154     . /usr/local/bin/virtualenvwrapper.sh
155 }
156 # }}}
157
158 # Mail {{{
159 mailpath=(
160     ~/mail/mbox"?Neue Nachrichten in =mbox"
161     ~/mail/arbeit"?Neue Nachrichten in =arbeit"
162 )
163 alias arr="mutt -f \=arbeit -e 'source ~/.mutt/accounts/stcnet.ru'"
164 alias rss="mutt -f \=rss"
165 bindkey -s "\eOP" " inc\n" # F1
166 # }}}
167
168 # Calculator {{{
169 autoload -U zcalc
170 alias zc="zcalc -r4"
171 # }}}
172
173 # Named directories {{{
174 . ~/.zhashd
175 # }}}
176
177 # Completion {{{
178 zstyle ":completion:*:functions" ignored-patterns "_*"
179 zstyle ":completion:*" matcher-list "" 'm:{a-z\-}={A-Z\_}' 'r:|?=** m:{a-z\-}={A-Z\_}'
180 _mycomp () {
181     [ "$words[1]" != "man" ] || { _man && return 0 }
182     [ $CURRENT -eq 1 ] && _command_names ||  _files && return 0
183     # MAGIC_EQUAL_SUBST {{{
184     [[ "$PREFIX" = *\=* ]] || return 1
185     compstate[parameter]="${PREFIX%%\=*}"
186     compset -P 1 "*="
187     _value
188     # }}}
189 }
190 zstyle ":completion:*" completer _mycomp _parameters
191 autoload -U compinit ; compinit -d /tmp/.zcompdump
192 zstyle ":completion:*:default" list-colors ""
193 autoload -U complist
194 # }}}
195
196 # Highlighting {{{
197 ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
198 . ~/work/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
199 typeset -A ZSH_HIGHLIGHT_STYLES
200 ZSH_HIGHLIGHT_STYLES[assign]="fg=yellow"
201 ZSH_HIGHLIGHT_STYLES[commandseparator]="fg=red"
202 ZSH_HIGHLIGHT_STYLES[single-hyphen-option]="fg=green,bold"
203 ZSH_HIGHLIGHT_STYLES[double-hyphen-option]="fg=green"
204 ZSH_HIGHLIGHT_STYLES[globbing]="fg=magenta"
205 ZSH_HIGHLIGHT_STYLES[global-alias]="fg=yellow,bold"
206 ZSH_HIGHLIGHT_STYLES[history-expansion]="fg=magenta"
207 ZSH_HIGHLIGHT_STYLES[redirection]="fg=red"
208 ZSH_HIGHLIGHT_STYLES[path]="fg=white,underline"
209 ZSH_HIGHLIGHT_STYLES[path_pathseparator]="fg=white,bold,underline"
210 # }}}
211
212 # Autosuggestion {{{
213 . ~/work/zsh-autosuggestions/zsh-autosuggestions.zsh
214 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=cyan"
215 # }}}