]> Sergey Matveev's repositories - dotfiles.git/blob - zsh/.zshrc
Useless INTERACTIVE_COMMENTS
[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
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|sdcv *|mmfileget *|arr)"
17 # }}}
18
19 # Vi mode {{{
20 bindkey -v
21 export KEYTIMEOUT=1
22 # }}}
23
24 # Home/end {{{
25 bindkey "^[[1~" beginning-of-line # Home
26 bindkey "^[[4~" end-of-line # End
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 ${BUFFER:gs/ /*/}
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 vi="vim"
79 alias m="less "
80 alias -g M="| less"
81 alias -g W="| wc -l | sed 's/ //g'"
82 alias mc="mc --nomouse"
83
84 f() {
85     find . -name "*$1*" -print
86 }
87
88 alias ssh="TERM=xterm ssh"
89 alias sshnm="ssh -S none"
90 ssht() {
91     ssh -C -t $1 tmux attach -t0
92 }
93 # }}}
94
95 # Faster movement {{{
96 cddotdot() {
97     cd ..
98     pwd
99     zle reset-prompt
100 }
101 zle -N cddotdot
102 bindkey "\eOQ" cddotdot # F2
103
104 popdquiet() {
105     popd
106     zle reset-prompt
107 }
108 zle -N popdquiet
109 bindkey "\eOS" popdquiet # F4
110 # }}}
111
112 # Git {{{
113 alias Ga="git add"
114 alias Gb="git branch"
115 alias Gc="git checkout"
116 alias Gd="git diff"
117 alias Gdc="git diff --cached"
118 alias Gs="git show --show-signature"
119 alias Gm="git diff --name-only --diff-filter=M"
120 alias Gam="git commit --amend"
121 alias Gl="git log --oneline --graph --decorate=short"
122 alias Gld="git log --format=format:'%ai %Cgreen%h%Creset %s'"
123
124 bindkey -s "\eOR" " git status --short\n" # F3
125 # }}}
126
127 # grep {{{
128 GREP_ARGS=(
129     --colour=always
130     --with-filename
131     --line-number
132     --dereference-recursive
133     --binary-files=without-match
134     --exclude-dir=.git
135     --exclude-dir=.tags
136 )
137 g() {
138     grep $GREP_ARGS $@ | less
139 }
140 GS() {
141     grep $GREP_ARGS $@ | sort --numeric-sort | less
142 }
143 alias -g G="| grep --colour=always"
144 alias gg="git grep "
145 # }}}
146
147 # GPG agent {{{
148 export GPG_TTY=$(tty)
149 # }}}
150
151 # Mail {{{
152 mailpath=(
153     ~/mail/mbox"?Neue Nachrichten in =mbox"
154     ~/mail/arbeit"?Neue Nachrichten in =arbeit"
155 )
156 alias arr="mutt -f \=arbeit -e 'source ~/.mutt/accounts/stcnet.ru'"
157 alias sent="mutt -f =sent-\`date '+%y-%m'\`"
158 bindkey -s "\eOP" " inc\n" # F1
159 # }}}
160
161 # Completion {{{
162 zstyle ":completion:*:functions" ignored-patterns "_*"
163 zstyle ":completion:*" matcher-list "" 'm:{a-z\-}={A-Z\_}' 'r:|?=** m:{a-z\-}={A-Z\_}'
164 _mycomp () {
165     [[ ${words[1]} != man ]] || { _man && return 0 }
166     [[ $CURRENT -eq 1 ]] && _command_names || _files && return 0
167     # MAGIC_EQUAL_SUBST {{{
168     [[ $PREFIX = *\=* ]] || return 1
169     compstate[parameter]=${PREFIX%%\=*}
170     compset -P 1 "*="
171     _value
172     # }}}
173 }
174 zstyle ":completion:*" completer _mycomp _parameters
175 autoload -U compinit ; compinit -d /tmp/.zcompdump
176 zstyle ":completion:*:default" list-colors ""
177 autoload -U complist
178 # }}}
179
180 # Highlighting {{{
181 ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
182 . ~/work/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
183 typeset -A ZSH_HIGHLIGHT_STYLES
184 ZSH_HIGHLIGHT_STYLES[assign]="fg=yellow"
185 ZSH_HIGHLIGHT_STYLES[commandseparator]="fg=red"
186 ZSH_HIGHLIGHT_STYLES[single-hyphen-option]="fg=green,bold"
187 ZSH_HIGHLIGHT_STYLES[double-hyphen-option]="fg=green"
188 ZSH_HIGHLIGHT_STYLES[globbing]="fg=magenta"
189 ZSH_HIGHLIGHT_STYLES[global-alias]="fg=yellow,bold"
190 ZSH_HIGHLIGHT_STYLES[history-expansion]="fg=magenta"
191 ZSH_HIGHLIGHT_STYLES[redirection]="fg=red"
192 ZSH_HIGHLIGHT_STYLES[path]="fg=white,underline"
193 ZSH_HIGHLIGHT_STYLES[path_pathseparator]="fg=white,bold,underline"
194 # }}}
195
196 # Autosuggestion {{{
197 . ~/work/zsh-autosuggestions/zsh-autosuggestions.zsh
198 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=cyan"
199 # }}}
200
201 # fzf {{{
202 cf() {
203     local dir=$(find -L ${1:-.} -mindepth 1 -path "*/\.git" -prune -o -type d -print |
204         fzf --height 40% --reverse --preview="tree -CN {}")
205     [[ -z $dir ]] || { print -s cd $dir ; cd $dir }
206 }
207 # }}}
208
209 # Named directories {{{
210 while read w ; do
211     w=(${(s/=/)w})
212     hash -d ${w[1]}=${~${w[2]}}
213 done < ~/.zhashd
214 # }}}
215
216 # autoenv {{{
217 . ~/work/zsh-autoenv/autoenv.zsh
218 # }}}
219
220 # Virtualenv {{{
221 venv() {
222     . /usr/local/bin/virtualenvwrapper.sh
223 }
224 # }}}