]> Sergey Matveev's repositories - dotfiles.git/blob - zsh/.zshrc
venv must be declared earlier than autoenv hook
[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 -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 mc="mc --nomouse"
84
85 f() {
86     bfs . -name "*$1*" -print
87 }
88
89 alias ssh="TERM=xterm ssh"
90 alias sshnm="ssh -S none"
91 ssht() {
92     ssh -C -t $1 tmux attach -t0
93 }
94
95 autoload -U zsh-mime-setup ; zsh-mime-setup
96 alias -s html=lynx
97
98 autoload -U zmv
99 # }}}
100
101 # Faster movement {{{
102 cddotdot() {
103     cd ..
104     pwd
105     zle reset-prompt
106 }
107 zle -N cddotdot
108 bindkey "\eOQ" cddotdot # F2
109
110 popdquiet() {
111     popd
112     zle reset-prompt
113 }
114 zle -N popdquiet
115 bindkey "\eOS" popdquiet # F4
116 # }}}
117
118 # Git {{{
119 alias Ga="git add"
120 alias Gb="git branch"
121 alias Gc="git checkout"
122 alias Gd="git diff"
123 alias Gdc="git diff --cached"
124 alias Gs="git show --show-signature"
125 alias Gm="git diff --name-only --diff-filter=M --relative"
126 alias Gam="git commit --amend"
127 alias Gl="git log --oneline --graph --decorate=short"
128 alias Gld="git log --format=format:'%ai %Cgreen%h%Creset %s'"
129
130 bindkey -s "\eOR" " git status --short\n" # F3
131 # }}}
132
133 # grep {{{
134 GREP_ARGS=(
135     --colour=always
136     --with-filename
137     --line-number
138     --dereference-recursive
139     --binary-files=without-match
140     --exclude-dir=.git
141     --exclude-dir=.tags
142 )
143 g() {
144     grep $GREP_ARGS $@ | less
145 }
146 alias -g G="| grep --colour=always"
147 alias gg="git grep "
148 # }}}
149
150 # GPG agent {{{
151 export GPG_TTY=$(tty)
152 # }}}
153
154 # Mail {{{
155 mailpath=(
156     ~/mail/mbox"?Neue Nachrichten in =mbox"
157     ~/mail/arbeit"?Neue Nachrichten in =arbeit"
158 )
159 alias arr="mutt -f =arbeit -e 'source ~/.mutt/accounts/stcnet.ru'"
160 alias sent="mutt -f =sent-\`date '+%y-%m'\`"
161 bindkey -s "\eOP" " inc\n" # F1
162 # }}}
163
164 # Completion {{{
165 zstyle ":completion:*" list-colors ""
166
167 zstyle ":completion:*:functions" ignored-patterns "_*"
168 zstyle ":completion:*:manuals" separate-sections true
169
170 zstyle ":completion:*" group-name ""
171 zstyle ":completion:*:messages" format "%d"
172 zstyle ":completion:*:warnings" format "%F{red}no matches: %d%f"
173 zstyle ":completion:*:*:*:*:descriptions" format "%B... %d%b"
174 zstyle ":completion:*:files:*:*:descriptions" format ""
175
176 zstyle ":completion:*" file-patterns "%p:globbed" "*"
177 zstyle ":completion:*" matcher-list "" "m:{a-z-}={A-Z_}" "r:|?=** m:{a-z-}={A-Z_}"
178 zstyle ":completion:*" completer _mycomp _parameters _ignored
179
180 _mycomp () {
181     [[ $CURRENT -eq 1 ]] && curcontext="${curcontext%:*:*}:-command-:" \
182         _command_names && return
183     local has_files
184     curcontext=:files:${curcontext#:*:} _files && has_files=1
185     [[ ${words[1]} == man ]] && curcontext=:man:${curcontext#:*:} \
186         _dispatch "" man man "" -default- && _value && return
187     [[ ${words[1]} == info ]] && curcontext=:info:${curcontext#:*:} \
188         _dispatch "" info info "" -default- && return
189     [[ $has_files ]] && return
190
191     # MAGIC_EQUAL_SUBST {{{
192     [[ $PREFIX = *\=* ]] || return 1
193     compstate[parameter]=${PREFIX%%\=*}
194     compset -P 1 "*="
195     _value
196     # }}}
197 }
198
199 autoload -U compinit ; compinit -d /tmp/.zcompdump
200 autoload -U complist
201 # }}}
202
203 # Highlighting {{{
204 ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
205 . ~/work/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
206 typeset -A ZSH_HIGHLIGHT_STYLES
207 ZSH_HIGHLIGHT_STYLES[assign]="fg=yellow"
208 ZSH_HIGHLIGHT_STYLES[commandseparator]="fg=red"
209 ZSH_HIGHLIGHT_STYLES[single-hyphen-option]="fg=green,bold"
210 ZSH_HIGHLIGHT_STYLES[double-hyphen-option]="fg=green"
211 ZSH_HIGHLIGHT_STYLES[globbing]="fg=magenta"
212 ZSH_HIGHLIGHT_STYLES[global-alias]="fg=yellow,bold"
213 ZSH_HIGHLIGHT_STYLES[history-expansion]="fg=magenta"
214 ZSH_HIGHLIGHT_STYLES[redirection]="fg=red"
215 ZSH_HIGHLIGHT_STYLES[path]="fg=white,underline"
216 ZSH_HIGHLIGHT_STYLES[path_pathseparator]="fg=white,bold,underline"
217 # }}}
218
219 # Autosuggestion {{{
220 . ~/work/zsh-autosuggestions/zsh-autosuggestions.zsh
221 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=cyan"
222 # }}}
223
224 # fzf {{{
225 cf() {
226     local dir=$(bfs -L ${1:-.} -mindepth 1 \
227         -path "*/\.git" -prune -o \
228         -path "*/\.redo" -prune -o \
229         -type d -print 2>/dev/null |
230             fzf --height 40% --reverse --preview="tree -CN {}")
231     [[ -z $dir ]] || { print -s cd $dir ; cd $dir }
232 }
233 # }}}
234
235 # Named directories {{{
236 while read w ; do
237     w=(${(s/=/)w})
238     hash -d ${w[1]}=${~${w[2]}}
239 done < ~/.zhashd
240 # }}}
241
242 # Virtualenv {{{
243 venv() {
244     . /usr/local/bin/virtualenvwrapper.sh
245 }
246 # }}}
247
248 # autoenv {{{
249 . ~/work/zsh-autoenv/autoenv.zsh
250 # }}}