]> Sergey Matveev's repositories - dotfiles.git/blob - zsh/.zshrc
Gm must be useful in non git root
[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
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 --relative"
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 alias -g G="| grep --colour=always"
141 alias gg="git grep "
142 # }}}
143
144 # GPG agent {{{
145 export GPG_TTY=$(tty)
146 # }}}
147
148 # Mail {{{
149 mailpath=(
150     ~/mail/mbox"?Neue Nachrichten in =mbox"
151     ~/mail/arbeit"?Neue Nachrichten in =arbeit"
152 )
153 alias arr="mutt -f =arbeit -e 'source ~/.mutt/accounts/stcnet.ru'"
154 alias sent="mutt -f =sent-\`date '+%y-%m'\`"
155 bindkey -s "\eOP" " inc\n" # F1
156 # }}}
157
158 # Completion {{{
159 zstyle ":completion:*:functions" ignored-patterns "_*"
160 zstyle ":completion:*" matcher-list "" 'm:{a-z\-}={A-Z\_}' 'r:|?=** m:{a-z\-}={A-Z\_}'
161 _mycomp () {
162     [[ ${words[1]} != man ]] || { _man && return 0 }
163     [[ $CURRENT -eq 1 ]] && _command_names || _files && return 0
164     # MAGIC_EQUAL_SUBST {{{
165     [[ $PREFIX = *\=* ]] || return 1
166     compstate[parameter]=${PREFIX%%\=*}
167     compset -P 1 "*="
168     _value
169     # }}}
170 }
171 zstyle ":completion:*" completer _mycomp _parameters
172 autoload -U compinit ; compinit -d /tmp/.zcompdump
173 zstyle ":completion:*:default" list-colors ""
174 autoload -U complist
175 # }}}
176
177 # Highlighting {{{
178 ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
179 . ~/work/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
180 typeset -A ZSH_HIGHLIGHT_STYLES
181 ZSH_HIGHLIGHT_STYLES[assign]="fg=yellow"
182 ZSH_HIGHLIGHT_STYLES[commandseparator]="fg=red"
183 ZSH_HIGHLIGHT_STYLES[single-hyphen-option]="fg=green,bold"
184 ZSH_HIGHLIGHT_STYLES[double-hyphen-option]="fg=green"
185 ZSH_HIGHLIGHT_STYLES[globbing]="fg=magenta"
186 ZSH_HIGHLIGHT_STYLES[global-alias]="fg=yellow,bold"
187 ZSH_HIGHLIGHT_STYLES[history-expansion]="fg=magenta"
188 ZSH_HIGHLIGHT_STYLES[redirection]="fg=red"
189 ZSH_HIGHLIGHT_STYLES[path]="fg=white,underline"
190 ZSH_HIGHLIGHT_STYLES[path_pathseparator]="fg=white,bold,underline"
191 # }}}
192
193 # Autosuggestion {{{
194 . ~/work/zsh-autosuggestions/zsh-autosuggestions.zsh
195 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=cyan"
196 # }}}
197
198 # fzf {{{
199 cf() {
200     local dir=$(bfs -L ${1:-.} -mindepth 1 \
201         -path "*/\.git" -prune -o \
202         -path "*/\.redo" -prune -o \
203         -type d -print 2>/dev/null |
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 # }}}