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