]> Sergey Matveev's repositories - dotfiles.git/blob - zsh/.zshrc
Comment about what key is binded
[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 setopt PIPE_FAIL
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     mode_vi=${${KEYMAP/vicmd/+}/(main|viins)/-}
55     [[ $timer ]] && timer_show=$(( $SECONDS - $timer ))
56     prompt="%2~|"
57     prompt+="%U${timer_show}%u|"
58     prompt+="%B%?%b"
59     prompt+="${mode_vi}"
60     prompt+="%B%F{magenta}%#%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 ssh="TERM=xterm ssh"
80 alias vi="vim"
81 alias more="less"
82 alias m="less "
83 alias -g M="| less"
84 alias -g W="| wc -l | sed 's/ //g'"
85 alias mc="mc --nomouse"
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 popdquiet() {
108     popd
109     zle reset-prompt
110 }
111 zle -N popdquiet
112 bindkey "\eOS" popdquiet # 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 alias Gl="git log --oneline --graph --decorate=short"
125 alias Gld="git log --format=format:'%ai %Cgreen%h%Creset %s'"
126
127 bindkey -s "\eOR" " git status --short\n" # F3
128 # }}}
129
130 # grep {{{
131 GREP_ARGS=(
132     --colour=always
133     --with-filename
134     --line-number
135     --dereference-recursive
136     --binary-files=without-match
137     --exclude-dir=.git
138     --exclude-dir=.tags
139 )
140 LESS_COLOURED=(less --RAW-CONTROL-CHARS)
141 g() {
142     grep $GREP_ARGS $@ | $LESS_COLOURED
143 }
144 GS() {
145     grep $GREP_ARGS $@ | sort --numeric-sort | $LESS_COLOURED
146 }
147 alias -g G="| grep --colour=always"
148 alias gg="git grep "
149 # }}}
150
151 # GPG agent {{{
152 export GPG_TTY=$(tty)
153 # }}}
154
155 # Virtualenv {{{
156 venv() {
157     . /usr/local/bin/virtualenvwrapper.sh
158 }
159 # }}}
160
161 # Mail {{{
162 mailpath=(
163     ~/mail/mbox"?Neue Nachrichten in =mbox"
164     ~/mail/arbeit"?Neue Nachrichten in =arbeit"
165 )
166 alias arr="mutt -f \=arbeit -e 'source ~/.mutt/accounts/stcnet.ru'"
167 alias sent="mutt -f =sent-\`date '+%y-%m'\`"
168 bindkey -s "\eOP" " inc\n" # F1
169 # }}}
170
171 # Completion {{{
172 zstyle ":completion:*:functions" ignored-patterns "_*"
173 zstyle ":completion:*" matcher-list "" 'm:{a-z\-}={A-Z\_}' 'r:|?=** m:{a-z\-}={A-Z\_}'
174 _mycomp () {
175     [[ ${words[1]} != man ]] || { _man && return 0 }
176     [[ $CURRENT -eq 1 ]] && _command_names || _files && return 0
177     # MAGIC_EQUAL_SUBST {{{
178     [[ $PREFIX = *\=* ]] || return 1
179     compstate[parameter]=${PREFIX%%\=*}
180     compset -P 1 "*="
181     _value
182     # }}}
183 }
184 zstyle ":completion:*" completer _mycomp _parameters
185 autoload -U compinit ; compinit -d /tmp/.zcompdump
186 zstyle ":completion:*:default" list-colors ""
187 autoload -U complist
188 # }}}
189
190 # Highlighting {{{
191 ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
192 . ~/work/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
193 typeset -A ZSH_HIGHLIGHT_STYLES
194 ZSH_HIGHLIGHT_STYLES[assign]="fg=yellow"
195 ZSH_HIGHLIGHT_STYLES[commandseparator]="fg=red"
196 ZSH_HIGHLIGHT_STYLES[single-hyphen-option]="fg=green,bold"
197 ZSH_HIGHLIGHT_STYLES[double-hyphen-option]="fg=green"
198 ZSH_HIGHLIGHT_STYLES[globbing]="fg=magenta"
199 ZSH_HIGHLIGHT_STYLES[global-alias]="fg=yellow,bold"
200 ZSH_HIGHLIGHT_STYLES[history-expansion]="fg=magenta"
201 ZSH_HIGHLIGHT_STYLES[redirection]="fg=red"
202 ZSH_HIGHLIGHT_STYLES[path]="fg=white,underline"
203 ZSH_HIGHLIGHT_STYLES[path_pathseparator]="fg=white,bold,underline"
204 # }}}
205
206 # Autosuggestion {{{
207 . ~/work/zsh-autosuggestions/zsh-autosuggestions.zsh
208 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=cyan"
209 # }}}
210
211 # fzf {{{
212 cf() {
213     local dir=$(find -L ${1:-.} -mindepth 1 -path "*/\.git" -prune -o -type d -print |
214         fzf --height 40% --reverse --preview="tree -CN {}")
215     [[ -z $dir ]] || { print -s cd $dir ; cd $dir }
216 }
217 # }}}
218
219 # Named directories {{{
220 while read w ; do
221     w=(${(s/=/)w})
222     hash -d ${w[1]}=${~${w[2]}}
223 done < ~/.zhashd
224 # }}}
225
226 # autoenv {{{
227 . ~/work/zsh-autoenv/autoenv.zsh
228 # }}}