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