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