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