]> Sergey Matveev's repositories - dotfiles.git/blob - zsh/.zshrc
Midnight Commander's useable mailcap-based extensions
[dotfiles.git] / zsh / .zshrc
1 # vim: foldmethod=marker:foldlevel=0
2
3 # Basic options {{{
4 setopt GLOB_STAR_SHORT GLOB_DOTS EXTENDED_GLOB
5 setopt NO_NOMATCH
6 setopt AUTO_PUSHD PUSHD_IGNORE_DUPS
7 setopt PIPE_FAIL
8 setopt MULTIBYTE
9
10 setopt RM_STAR_SILENT
11 export LISTMAX=9999
12 # }}}
13
14 # History options {{{
15 setopt APPEND_HISTORY SHARE_HISTORY INC_APPEND_HISTORY HIST_IGNORE_ALL_DUPS
16 setopt HIST_IGNORE_SPACE
17 HISTORY_IGNORE="(yt* *|t *|t|sdcv *|mmfileget *|arr)"
18 # }}}
19
20 # Vi mode {{{
21 bindkey -v
22 export KEYTIMEOUT=1
23 # }}}
24
25 # Home/end {{{
26 bindkey "^[[1~" beginning-of-line # Home
27 bindkey "^[[4~" end-of-line # End
28 # }}}
29
30 # Command-line editing {{{
31 autoload -U edit-command-line
32 zle -N edit-command-line
33 bindkey -M vicmd v edit-command-line
34 # }}}
35
36 # History search {{{
37 autoload -U history-search-end
38 zle -N history-beginning-search-backward-end history-search-end
39 zle -N history-beginning-search-forward-end history-search-end
40 bindkey "^[[A" history-beginning-search-backward-end
41 bindkey "^[[B" history-beginning-search-forward-end
42
43 beginning-history-incremental-pattern-search-backward() {
44     zle history-incremental-pattern-search-backward ${BUFFER:gs/ /*/}
45 }
46 zle -N beginning-history-incremental-pattern-search-backward
47 bindkey "^[[1;2A" beginning-history-incremental-pattern-search-backward
48 bindkey -M isearch "^[[A" history-incremental-pattern-search-backward
49 bindkey -M isearch "^[[B" history-incremental-pattern-search-forward
50 # }}}
51
52 # Prompt {{{
53 function zle-line-init zle-keymap-select {
54     local state="%#" timer_val="?"
55     [[ ${KEYMAP} == vicmd ]] && state="+"
56     [[ $timer ]] && timer_val=$(( $SECONDS - $timer ))
57     prompt="%2~ "
58     prompt+="%U${timer_val}%u|"
59     prompt+="%B%?%b"
60     prompt+="%B%F{magenta}${state}%f%b "
61     PS1=$prompt
62     zle reset-prompt
63 }
64 zle -N zle-line-init
65 zle -N zle-keymap-select
66
67 preexec() {
68     timer=$SECONDS
69 }
70
71 precmd() {
72     printf "\a\033]2;\033\\"
73 }
74 # }}}
75
76 # Aliases {{{
77 alias l="ls -AF "
78 alias ll="ls -D \"%Y-%m-%d %H:%M\" -AFl "
79 alias vi="vim"
80 alias m="less "
81 alias -g M="| less"
82 alias -g W="| wc -l | sed 's/ //g'"
83 alias -g T="| tai64nlocal"
84 alias -g DN=">/dev/null"
85 alias -g 2DN="2>/dev/null"
86 alias -g DNA=">&/dev/null"
87 alias mc="mc --nomouse"
88
89 f() {
90     bfs . -name "*$1*" -print
91 }
92
93 alias ssh="TERM=xterm ssh"
94 alias sshnm="ssh -S none"
95 ssht() {
96     local t="-t 0"
97     TERM=xterm ssh -C -t $1 "tmux has-session $t && tmux attach-session $t || tmux new-session $t"
98 }
99
100 autoload -U zsh-mime-setup ; zsh-mime-setup
101 alias -s html=lynx
102
103 autoload -U zmv
104 # }}}
105
106 # Faster movement {{{
107 cddotdot() {
108     cd ..
109     pwd
110     zle reset-prompt
111 }
112 zle -N cddotdot
113 bindkey "\eOQ" cddotdot # F2
114
115 popdquiet() {
116     popd
117     zle reset-prompt
118 }
119 zle -N popdquiet
120 bindkey "\eOS" popdquiet # F4
121 # }}}
122
123 # Git {{{
124 alias Ga="git add"
125 alias Gb="git branch"
126 alias Gc="git checkout"
127 alias Gd="git diff"
128 alias Gdc="git diff --cached"
129 alias Gs="git show --show-signature"
130 alias Gm="git diff --name-only --diff-filter=M --relative"
131 alias Gam="git commit --amend"
132 alias Gl="git log --oneline --graph --decorate=short"
133 alias Gld="git log --format=format:'%ai %Cgreen%h%Creset %s'"
134
135 bindkey -s "\eOR" " git status --short\n" # F3
136 # }}}
137
138 # grep {{{
139 GREP_ARGS=(
140     --devices=skip
141     --colour=always
142     --with-filename
143     --line-number
144     --dereference-recursive
145     --binary-files=without-match
146     --exclude-dir=.git
147     --exclude-dir=.tags
148 )
149 g() {
150     grep $GREP_ARGS $@ | less
151 }
152 alias -g G="| grep --colour=always"
153 alias gg="git grep "
154 # }}}
155
156 # GPG agent {{{
157 export GPG_TTY=$(tty)
158 # }}}
159
160 # Mail {{{
161 mailpath=(
162     ~/mail/mbox"?Neue Nachrichten in =mbox"
163     ~/mail/arbeit"?Neue Nachrichten in =arbeit"
164 )
165 alias arr="mutt -f =arbeit -e 'source ~/.mutt/accounts/stcnet.ru'"
166 alias sent="mutt -f =sent-\`date '+%y-%m'\`"
167 bindkey -s "\eOP" " inc\n" # F1
168 # }}}
169
170 # Completion {{{
171 zstyle ":completion:*" list-colors ""
172
173 zstyle ":completion:*:functions" ignored-patterns "_*"
174 zstyle ":completion:*:manuals" separate-sections true
175
176 zstyle ":completion:*" group-name ""
177 zstyle ":completion:*:messages" format "%d"
178 zstyle ":completion:*:warnings" format "%F{red}no matches: %d%f"
179 zstyle ":completion:*:*:*:*:descriptions" format "%B... %d%b"
180 zstyle ":completion:*:files:*:*:descriptions" format ""
181
182 zstyle ":completion:*" file-patterns "%p:globbed" "*"
183 zstyle ":completion:*" matcher-list "" "m:{a-z-}={A-Z_}" "r:|?=** m:{a-z-}={A-Z_}"
184 zstyle ":completion:*:man:*:*:*" matcher-list "" "m:{a-zA-Z}={A-Za-z} l:|=* r:|=*"
185 zstyle ":completion:*" completer _mycomp _mycomp_man:man _parameters _ignored
186
187 _mycomp () {
188     [[ $CURRENT -eq 1 ]] && curcontext="${curcontext%:*:*}:-command-:" \
189         _command_names && return
190     [[ $IPREFIX =~ ~.* ]] && _tilde && return
191     local has_files
192     curcontext=:files:${curcontext#:*:} _files && has_files=1
193     [[ $has_files ]] && return
194
195     # MAGIC_EQUAL_SUBST {{{
196     [[ $PREFIX = *\=* ]] || return 1
197     compstate[parameter]=${PREFIX%%\=*}
198     compset -P 1 "*="
199     _value
200     # }}}
201 }
202
203 _mycomp_man () {
204     [[ ${words[1]} == man ]] && curcontext=:man:${curcontext#:*:} \
205         _dispatch "" man man "" -default- && _value && return
206     [[ ${words[1]} == info ]] && curcontext=:info:${curcontext#:*:} \
207         _dispatch "" info info "" -default- && return
208 }
209
210 autoload -U compinit ; compinit -d /tmp/.zcompdump
211 autoload -U complist
212 # }}}
213
214 # Highlighting {{{
215 ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
216 . ~/work/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
217 typeset -A ZSH_HIGHLIGHT_STYLES
218 ZSH_HIGHLIGHT_STYLES[assign]="fg=yellow"
219 ZSH_HIGHLIGHT_STYLES[commandseparator]="fg=red"
220 ZSH_HIGHLIGHT_STYLES[single-hyphen-option]="fg=green,bold"
221 ZSH_HIGHLIGHT_STYLES[double-hyphen-option]="fg=green"
222 ZSH_HIGHLIGHT_STYLES[globbing]="fg=magenta"
223 ZSH_HIGHLIGHT_STYLES[global-alias]="fg=yellow,bold"
224 ZSH_HIGHLIGHT_STYLES[history-expansion]="fg=magenta"
225 ZSH_HIGHLIGHT_STYLES[redirection]="fg=red"
226 ZSH_HIGHLIGHT_STYLES[path]="fg=white,underline"
227 ZSH_HIGHLIGHT_STYLES[path_pathseparator]="fg=white,bold,underline"
228 # }}}
229
230 # Autosuggestion {{{
231 . ~/work/zsh-autosuggestions/zsh-autosuggestions.zsh
232 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=cyan"
233 # }}}
234
235 # fzf {{{
236 cf() {
237     local dir=$(bfs -L ${1:-.} -mindepth 1 \
238         -path "*/\.git" -prune -o \
239         -path "*/\.redo" -prune -o \
240         -type d -print 2>/dev/null |
241             fzf --height 40% --reverse --preview="tree -CN {}")
242     [[ -z $dir ]] || { print -s cd $dir ; cd $dir }
243 }
244 # }}}
245
246 # Named directories {{{
247 while read w ; do
248     w=(${(s/=/)w})
249     hash -d ${w[1]}=${~${w[2]}}
250 done < ~/.zhashd
251 # }}}
252
253 # Midnight commander extensions configuration {{{
254 [ -s $XDG_CONFIG_HOME/mc/mc.ext ] || {
255     mkdir $XDG_CONFIG_HOME/mc/
256     cp ~dot/mc/mc.ext $XDG_CONFIG_HOME/mc/
257 }
258 # }}}
259
260 # Virtualenv {{{
261 venv() {
262     . /usr/local/bin/virtualenvwrapper.sh
263 }
264 # }}}
265
266 # autoenv {{{
267 . ~/work/zsh-autoenv/autoenv.zsh
268 # }}}